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

Implement a vector element-wise add every column of mat

Tags: None
(comma "," separated)
kde-crazy
Registered Member
Posts
20
Karma
0
How to implement a (n,1) vector element-wise add every column of a (n,m) matrix, which results in a (n,m) matrix?

Image

Last edited by kde-crazy on Tue Jan 12, 2016 9:36 am, edited 1 time in total.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Your question is not very clear, but I guess you are looking for:

Code: Select all
VectorXd v(n);
MatrixXd A(n,m), B(n,m);
B = A.colwise() + v;


or

Code: Select all
B = A + v.rowwise().replicate(m);


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft