Registered Member
|
Hello, I have been trying to implement some ML algorithms using Eigen lately. For some of them, I need to remember the result of comparing an Array wit a Scalar.
when I do the following:
The program just writes a vector of ones and zeros, where ones are found in rows which had the values scalar in them in the begining. Also, when I do the following:
There are no bugs and the array arr has appropriate values. but when I do the following:
I get a long line of errors form compiler :
I suppose the result of (m == scalar) has some different type, which cannot be cast to an ArrayXd, but I don't know what is this type. I couldn't find any references in the tutorial or documentation on how to deal with such a problem, please help. |
Moderator
|
the result of a comparison is a bool, so you need an array of bool, ArrayXb.
|
Registered Member
|
Thank you for your answer ggael.
Is there a nice way of casting it to double? Basically I have a Vector of doubles Y, and I want to get a Vector o values 0/1 indicating if values of Y are equal to a given double constant k. I also want this 0/1 values to be doubles, and possibly to do it with Eigen syntax for optimization, and not just use a for loop. |
Moderator
|
of course: (whatever matrix or array expression).cast<double>()
|
Registered Member
|
This is exactly what I was looking for and solves my problem elegantly! Thank you very much ggael!
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]