PCA computation on 2D vectors of type double <p>I am trying to run PCA on a dataset which I have stored into a 2D vector from a file as follows:</p> <pre><code>std::vector&lt;std::vector&lt;double&gt; &gt; tmpVec; while(std::getline(file, numStream)) { std::istringstream buffer(numStream); std::vector&lt;double&gt; line((std::istream_iterator&lt;double&gt;(buffer)), std::istream_iterator&lt;double&gt;()); tmpVec.push_back(line); i++; } </code></pre> <p>Now I need to run PCA on this for which according to my understanding I need to convert this to type cv::Mat. This is being done as follows: </p> <pre><code>cv::Mat dst(row, col, CV_64F, &amp;tmpVec); </code></pre> <p>And thrn i run PCA on it as:</p> <pre><code>cv::PCA pca(dst, cv::Mat(), CV_PCA_DATA_AS_ROW, 2); </code></pre> <p>When I try printing it out on screen after PCA computation i end up with garbage values. I just need to figure out how to run PCA on a 2D double vector. Any help with this or pointing me in the right direction would be great. Thanks in advance.</p>