Reputation: 69
I have a 2D vector that contains 138 vectors. I need to break out each of the 138 vectors in order to calculate the dot product. I have a working dot product function, but I'm having a hard time breaking out the individual vectors from my initial 2D vectors. Here's what I have:
for (unsigned i = 0u; i != templateVector.size(); ++i) {
for(vector<double> vec : templateVector){
// cout << face.quickSort(vec, 0.0, 9.0);
cout << "\nscalar_product: Index[" << i <<"] " << face.scalar_product(vec, queryVector);
}
std::cout << "\n";
}
It ends up printing the dot product of each vector (index i) 138 times. My templateVector is the vector that contains 138 "vec" vectors, each of which has 5,632 doubles. My queryVector contains 5,632 doubles as well.
Thanks in advance for your help.
Upvotes: 0
Views: 80
Reputation: 23793
Your outter loop is unnecessary (and is the reason why you see 138 times the output for each vector), and you inner for-range loop unnecessarily copies the vectors.
Simply do :
for(auto& vec : templateVector){
cout << "\nscalar_product: Index[" << i <<"] " << face.scalar_product(vec, queryVector);
}
Upvotes: 1