sure there are many ways:
assert(v1.size() == v2.size());
for (auto&& i = 0; i < v1.size(); ++i) {
acc += v1[i]*v2[i];
}
but there is a zip
operator in python, so python code would be easy as following codes:
acc = accumulate([ele1 * ele2 for ele1, ele2 in zip(v1, v2)])
my question is: are there any similar approaches to write some codes as styled as python code? especially by std::algorithm library.
Aucun commentaire:
Enregistrer un commentaire