For example if I have a 4 by 4 matrix. Is there a way to create another matrix (or a view into original matrix, even better), that is only rows 1 and 3 of original matrix.
I only see how to extract a row, or a block, but no what I mentioned above. Here is my code:
#include <iostream>
#include <Eigen/Dense>
using namespace Eigen;
int main()
{
Matrix4f m = Matrix4f::Random();
std::cout << "Matrix : " << std::endl;
std::cout << m << std::endl;
std::cout << "row" << std::endl;
std::cout << m.row(1) << std::endl;
std::cout << "block : " << std::endl;
std::cout << m.block(1,0,2,4) << std::endl;
return 0;
}
A potential solution is to pre-multiply my matrix by a matrix of ones and zeros,
z = ([[ 0., 1., 0., 0.],
[ 0., 0., 0., 1.]])
z * m would give me what I want, but is there a better solution.
Edit:
A possible application of what I want to do:
Let's say I have matrices A(m x n)
and B(n x k)
. I want to sample from A
and multiply by B
, say I take 1/5th
of A's rows A'(m/5 X n) * B(n x k)
is what I am after. I don't need A'
itself, it is that product that I am after.