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

Matrix's row array multiplication with an Array

Tags: None
(comma "," separated)
mehrdadh
Registered Member
Posts
26
Karma
0
Hello,

I have used Eigen a lot. But I am having a problem that I cannot understand.

Imagine this:

Code: Select all
int m = 40;
int n = 50;
ArrayXd s1 = ArrayXd::Ones(m);
MatrixXd m1 = MatrixXd::Random(n,m);

double sums = (m1.row(0).array()*s1).array().sum();    // this line doesn't work, WHY ?



Could you let me know how can I do a coefficient wise multiplication of a row of a column-major matrix with an array ?

Thanks
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
You are multiplying a row (1 x m) with a column array (m x 1), so you can do:

double sums = (m1.row(0).transpose().array()*s1).sum();

or:

sums = m1.row() * s1.matrix(); // classic inner product

or:

sums = m1.row().dot(s1.matrix());


Bookmarks



Who is online

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