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

Rowwise Unary Operator in Eigen

Tags: None
(comma "," separated)
skn123
Registered Member
Posts
8
Karma
0

Rowwise Unary Operator in Eigen

Sun Jun 28, 2015 3:13 pm
Hi, I have a problem as follows:
a.) A Dense matrix: e.g.,
Code: Select all
A = EigenXd M(5,2) = {0,1,2,3,4,5,6,7,8,9}

b.) If I want to compute a row-wise mean of this matrix; which is easy
c.) Now, Is there some function in Eigen that I can use in conjunction with unaryExpr but operated along the rows? Say based on the mean of every row, I would like to determine if an element is greater than or less than the mean of every row?

Thanks for your help. Its been a pleasure of using EIgen and converting all data structures into Eigen
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Rowwise Unary Operator in Eigen

Tue Jul 07, 2015 1:10 pm
You cannot apply custom functors row-wise or column-wise, but it your case you can use replicate to achieve your goal:

MatrixXb mask = A > A.rowwise().mean().rowise().replicate(A.cols())

This constructs a matrix of bool such that:

mask(i,j)==true <=> A(i,j) > A.row(i).mean()
skn123
Registered Member
Posts
8
Karma
0

Re: Rowwise Unary Operator in Eigen

Thu Jul 09, 2015 1:59 pm
Hello Gael
Thanks for the information. I was trying to using this for computing the KL-divergence between two vectors that are located in two matrices. Is there some way we can vectorize this using Eigen?
skn123
Registered Member
Posts
8
Karma
0

Re: Rowwise Unary Operator in Eigen

Tue Aug 11, 2015 2:24 pm
Gael
I have a question regarding this post:

viewtopic.php?f=74&t=91378

In my Matrix listed above, I would like to do the following:
(Using Matlab notation)
for i = 1:5
x{i} = find (M(i,:) > mean(M(i,:)));
y{i} = find (M(i,:) <= mean(M(i,:)));
end

Is there any way I can effect this using Eigen other than writing a for-loop?

If I do want to write a custom operator for rowwise operation, where should I start?


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]