Tutorial_ReductionsVisitorsBroadcasting_maxnorm.cpp 502 B

1234567891011121314151617181920
  1. #include <iostream>
  2. #include <Eigen/Dense>
  3. using namespace std;
  4. using namespace Eigen;
  5. int main()
  6. {
  7. MatrixXf mat(2,4);
  8. mat << 1, 2, 6, 9,
  9. 3, 1, 7, 2;
  10. MatrixXf::Index maxIndex;
  11. float maxNorm = mat.colwise().sum().maxCoeff(&maxIndex);
  12. std::cout << "Maximum sum at position " << maxIndex << std::endl;
  13. std::cout << "The corresponding vector is: " << std::endl;
  14. std::cout << mat.col( maxIndex ) << std::endl;
  15. std::cout << "And its sum is is: " << maxNorm << std::endl;
  16. }