Skip to content

Instantly share code, notes, and snippets.

@kevinhughes27
Last active December 21, 2015 18:29
Show Gist options
  • Save kevinhughes27/6347606 to your computer and use it in GitHub Desktop.
Save kevinhughes27/6347606 to your computer and use it in GitHub Desktop.
NumPy style printing in C++ for Eigen 3
using namespace Eigen;
typedef Matrix< float64_t, Dynamic, Dynamic, ColMajor > EMatrix;
using std::cout;
using std::endl;
void print(EMatrix A)
{
int n = A.rows();
int m = A.cols();
// print small matrices with default eigen3 cout
if(n < 2 || m < 3)
{
cout << A << endl;
return;
}
// NumPy style print
cout << "[";
cout << "[ " << A(0,0) << " " << A(0,1) << " " << A(0,2) << " ..., "
<< A(0,m-3) << " " << A(0,m-2) << " " << A(0,m-1) << " ]";
cout << endl;
cout << "[ " << A(n,0) << " " << A(n,1) << " " << A(n,2) << " ..., "
<< A(n,m-3) << " " << A(n,m-2) << " " << A(n,m-1) << " ]";
cout << "]" << endl;
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment