Eigen permutate columns/rows

#include <iostream>
#include "Eigen/Dense"
#include "eigen_consts.H"
#include "eigen_test.H"


using namespace std;
using namespace Eigen;

int main()
{
	MatrixXf A(3,4);
	A << 1,2,3,4,5,6,7,8,9,10,11,12;
	cout << A << endl;

	PermutationMatrix<4, 4> permX(4);
	permX.setIdentity();
	// Your permutation
	cout << permX.indices()<< endl;
	permX.indices() << 1,0,2,3;
	// Permutate rows
	// A = permX * A;
	A = (A * permX).rightCols(2);
	cout << A << endl;

	return 0;
}
posted @ 2020-11-21 01:25  2021年的顺遂平安君  阅读(96)  评论(0编辑  收藏  举报