Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between norm, normalize and normalized in eigen

Tags:

c++

eigen

Suppose I have a MatrixXcf called A. I want to replace elements of every column by normalized one relative to the corresponding column. I've written following code but it's not true!

for (int i = 0; i < A.cols(); i++)
    A.col(i).real.array() = A.col(i).real().array()/A.col(i).real().norm();

and another question, what's difference between norm(), normalize() and normalized() in Eigen?

like image 223
Saeid Avatar asked Dec 29 '17 07:12

Saeid


1 Answers

Firstly, you can normalize in place with normalize, so your code should be:

for (int i = 0; i < A.cols(); i++)
    A.col(i).normalize();

Secondly:

  1. normalize - Normalizes a compile time known vector (as in a vector that is known to be a vector at compile time) in place, returns nothing.
  2. normalized - Returns the above as a constructed copy, doesnt affect the class. You can use it to assign - Vector normCopy = vect.normalized().
  3. norm - Returns the norm value of the matrix. Ie, the square root of the sum of the square of all the matrix entries.

So the difference is really, what each function returns for you.

like image 106
Fantastic Mr Fox Avatar answered Oct 22 '22 23:10

Fantastic Mr Fox