If you are using opencv3, you can print Mat like python numpy style
:
Mat xTrainData = (Mat_<float>(5,2) << 1, 1, 1, 1, 2, 2, 2, 2, 2, 2);
cout << "xTrainData (python) = " << endl << format(xTrainData, Formatter::FMT_PYTHON) << endl << endl;
Output as below, you can see it'e more readable, see here for more information.

But in most case, there is no need to output all the data in Mat, you can output by row range like 0 ~ 2 row:
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <iomanip>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
//row: 6, column: 3,unsigned one channel
Mat image1(6, 3, CV_8UC1, 5);
// output row: 0 ~ 2
cout << "image1 row: 0~2 = "<< endl << " " << image1.rowRange(0, 2) << endl << endl;
//row: 8, column: 2,unsigned three channel
Mat image2(8, 2, CV_8UC3, Scalar(1, 2, 3));
// output row: 0 ~ 2
cout << "image2 row: 0~2 = "<< endl << " " << image2.rowRange(0, 2) << endl << endl;
return 0;
}
Output as below:
