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

Adding a constant number to all the elements of a vector

Tags: None
(comma "," separated)
marvisiyer
Registered Member
Posts
21
Karma
0
What is the most efficient way to add a constant number to all the elements of a vector in Eigen?

One obvious way is to use a for loop.

The other option is to do
Code: Select all
myconstant*VectorXd::Ones(n) + myvector;


Is there a better way?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
you have to move to array world:

myvector.array() + myconstant


Bookmarks



Who is online

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