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

squaring an eigen vectorXf

Tags: None
(comma "," separated)
pamparana
Registered Member
Posts
18
Karma
0

squaring an eigen vectorXf

Sat Nov 29, 2014 8:24 pm
I am having some very strange behaviour with multiplying Eigen VectorXf objects. So, I have something like:

Code: Select all
Eigen::VectorXf gradient;
// Resize and fill gradient.

Eigen::VectorXf grad_2 = gradient * gradient; // This contains nonsensical values



The idea is that I would get the element wise squaring of the vector. So, the gradient vector is fine and contains the correct values but the grad_2 object is completely nonsensical (or computes some other unexpected vector product for me) and basically just contains noise. Am I doing something terribly wrong here? I would like to do an element wise multiplication between two vectors.

Thanks,
Luca
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: squaring an eigen vectorXf

Mon Dec 01, 2014 2:24 pm
You are multiplying a Nx1 matrix with a Nx1 matrix which is undefined in terms of matrix algebra. grad_2 = gradient.cwiseAbs2() will do the job.

See http://eigen.tuxfamily.org/dox-devel/gr ... Class.html for more on this topic.


Bookmarks



Who is online

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