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

rowwise multiply then sum

Tags: None
(comma "," separated)
johnm1019
Registered Member
Posts
46
Karma
0

rowwise multiply then sum

Wed Feb 06, 2013 4:44 pm
I am trying to doing this right now
Code: Select all
Eigen::ArrayXf exposureEfficiencies;
Eigen::MatrixXf m_systemMatrix.getMatrix();

Code: Select all
exposureEfficiencies = (m_systemMatrix.getMatrix().rowwise() * exposureEfficiencies).colwise().sum();

it just won't compile for me :-\

Assuming my matrix has I rows and J columns...
I want to multiply each ROW Matrix(i) of the matrix by the scalar Array(i) and then take the COL-wise sum resulting in a new Array of size J. (YES, this should resize exposureEfficiencies from size I to size J)
GeorgeKnight
Registered Member
Posts
15
Karma
0

Re: rowwise multiply then sum

Thu Feb 07, 2013 12:29 pm
Is the following what you're looking for?

Code: Select all
ArrayXXf M(2,3);
M << 1., 2., 3.,
     4., 5., 6.;
ArrayXf A(3);
A << 10., 20., 30.;
   
cout << (M.rowwise() * A.transpose()).colwise().sum() << endl;


which gives

50 140 270.
johnm1019
Registered Member
Posts
46
Karma
0

Re: rowwise multiply then sum

Thu Feb 07, 2013 12:47 pm
GeorgeKnight wrote:Is the following what you're looking for?

Code: Select all
ArrayXXf M(2,3);
M << 1., 2., 3.,
     4., 5., 6.;
ArrayXf A(3);
A << 10., 20., 30.;
   
cout << (M.rowwise() * A.transpose()).colwise().sum() << endl;


which gives

50 140 270.

This is exactly what I need. 8)
Although this still isn't compiling....
Code: Select all
exposureEfficiencies = (m_systemMatrix.getMatrix().array().rowwise() * exposureEfficiencies.transpose()).colwise().sum();

Is it possible that ArrayWrapper is missing an overload?
jitseniesen
Registered Member
Posts
204
Karma
2

Re: rowwise multiply then sum

Thu Feb 07, 2013 1:57 pm
johnm1019 wrote:Although this still isn't compiling....
Code: Select all
exposureEfficiencies = (m_systemMatrix.getMatrix().array().rowwise() * exposureEfficiencies.transpose()).colwise().sum();

Is it possible that ArrayWrapper is missing an overload?

That should compile, assuming that exposureEfficiencies is of type ArrayXf and m_systemMatrix.getMatrix() returns a MatrixXf. Could you perhaps post a small self-contained example showing the error?
GeorgeKnight
Registered Member
Posts
15
Karma
0

Re: rowwise multiply then sum

Thu Feb 07, 2013 3:19 pm
The following compiles fine on my computer:

Code: Select all
MatrixXf m_systemMatrix(2,3);
m_systemMatrix << 1., 2., 3.,
                  4., 5., 6.;
ArrayXf exposureEfficiencies(3);
exposureEfficiencies << 10., 20., 30.;

exposureEfficiencies = (m_systemMatrix.array().rowwise() *                         exposureEfficiencies.transpose()).colwise().sum();
       
cout << exposureEfficiencies << endl;


The difference with your code is the "getMatrix()".


Bookmarks



Who is online

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