This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Can I do x(x>0) like matlab?

Tags: None
(comma "," separated)
sth4nth
Registered Member
Posts
13
Karma
0

Can I do x(x>0) like matlab?

Fri Oct 15, 2010 7:01 pm
I'm a newbie for eigen library. Here is a silly question, which I could not find the answer from the doc.
Is there an way to access a subset of entries of vector or matrix using indicator or index like matlab? For example, for such an expression
x(x>0)=0;
how can I do it in eigen without using for loop?
Thanks
IsmaelNetzel
Registered Member
Posts
6
Karma
0

Re: Can I do x(x>0) like matlab?

Sat Oct 16, 2010 11:47 am
I need the same functionality like you.
I don't have an expression, but a vector containing indices. And then I would like to compose a new matrix containing the rows taken at the indices from another big matrix.

something like this:
Code: Select all
VectorXf idx = something.row(i);
MatrixXf ordered = ??; //othermatrix(idx,:) in Matlab


Have you found out something already? I searched the doc for something like a filter to be applied on a matrix or a way to access multiple rows/columns but have not found anything usefull. I think in the meanwhile I have to copy it manually in a loop.

Ismael
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: Can I do x(x>0) like matlab?

Sat Oct 16, 2010 12:50 pm
sth4nth wrote:I'm a newbie for eigen library. Here is a silly question, which I could not find the answer from the doc.
Is there an way to access a subset of entries of vector or matrix using indicator or index like matlab? For example, for such an expression
x(x>0)=0;
how can I do it in eigen without using for loop?
Thanks



Like this (here x is a MatrixXf of size n-by-p):

(x.array() >= 0.f).select(x, MatrixXf::Zero(n,p));


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: Can I do x(x>0) like matlab?

Sat Oct 16, 2010 12:53 pm
IsmaelNetzel wrote:I need the same functionality like you.
I don't have an expression, but a vector containing indices. And then I would like to compose a new matrix containing the rows taken at the indices from another big matrix.

something like this:
Code: Select all
VectorXf idx = something.row(i);
MatrixXf ordered = ??; //othermatrix(idx,:) in Matlab


Have you found out something already? I searched the doc for something like a filter to be applied on a matrix or a way to access multiple rows/columns but have not found anything usefull. I think in the meanwhile I have to copy it manually in a loop.

Ismael


We don't currently have this feature but it's been asked for many times and even discussed on the mailing list...


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rockscient