Registered Member
|
Hi you all,
I'm wondering if is possible in Eigen to randomize the order of rows (or columns) in a MatrixX. Thanks again for your great software! |
Registered Member
|
This could be a stupid solution, but to use it I need to create a temporary object.
I understand that this is not the optimal solution because we need to create two objects, but I'm wondering if std::random_shuffle() can help in this case acting directly on rows of MatrixXd.
Last edited by linello on Fri Apr 15, 2011 1:59 pm, edited 1 time in total.
|
Registered Member
|
One possibility is to construct a vector containing 0, 1, 2, 3, ..., permute this vector with random_shuffle, and then apply the permutation represented by the vector to the matrix:
It uses a vector indices, but I think that's acceptable. More problematic may be that a temporary matrix is created in the last line.
I came up with the following code, which does not work:
The idea here is to fill the std::vector with the expression objects returned by A.row(i) instead of converting it to a Eigen::VectorXd. However, this does not work when I try it. I don't know why. |
Moderator
|
the above statement is evaluated "in-place", without any temporary. So this is definitely the right way to go. |
Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], q.ignora