Search
 
SCRIPT & CODE EXAMPLE
 

CPP

get shape of eigen matrix

#include <iostream>
#include <sstream> // <-- Added
#include "Eigen/Dense"

using std::cout;
using std::endl;
using std::string;
using std::ostringstream; // <-- Added
using Eigen::MatrixXd;
using Eigen::EigenBase;   // <-- Added

template <typename Derived>
std::string get_shape(const EigenBase<Derived>& x)
{
    std::ostringstream oss;
    oss  << "(" << x.rows() << ", " << x.cols() << ")";
    return oss.str();
}

int main(int argc, char**argv)
{
    MatrixXd m(2, 3);
    m << 1, 2, 3, 10, 20, 30;

    cout << "shape: " << get_shape(m) << endl;
    // shape: (2, 3)

    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to add values in empty array using python 
Cpp :: c++ arrays 
Cpp :: rgb(100,100,100,0.5) validation c++ 
Cpp :: hamming c++ 
Cpp :: Corong_ExerciseNo3(1) 
Cpp :: solve diamond inheritance c++ 
Cpp :: Chef and the Wildcard Matching codechef solution in c++ 
Cpp :: set(W) 
Cpp :: for llop in c++ 
Cpp :: cudaMalloc 
Cpp :: GCD(x, yz) 
Cpp :: what is vector capacity in c++ 
Cpp :: how to get steam id c++ 
Cpp :: find number of 1s in a binary cv::mat image 
Cpp :: c++ start thread later 
Cpp :: C++ Function-style Casting 
Cpp :: C++ operation 
Cpp :: declare static table filled cpp 
Cpp :: catalan numbers c++ 
Cpp :: ‘npos’ is not a member of ‘std’ 
Cpp :: time optimisation c++ 
Cpp :: cpp console progressbar 
Cpp :: hola mundo c++ 
Cpp :: multilevel inheritance in c++ private method 
Cpp :: Smooth Poti values on Arduino 
Cpp :: c++ Is there still a need to provide default constructors to use STL containers 
Cpp :: int a=0; int b=30; 
Cpp :: c++ auto loop 
Cpp :: default access specifier in c++ 
Cpp :: c++ destructor 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =