一:功能
求内积, 给定两个向量x,y,内积公式如下:
二:用法
#include <iostream>
#include <vector>
#include <numeric>
int main() {
std::vector<int> heights{1, 2, 3, 4, 5};
std::vector<int> widths{2, 3, 4, 5, 6};
auto total_area = std::inner_product(heights.begin(), heights.end(),
widths.begin(), 0);
std::cout << "total_area == " << total_area << "\n";
total_area = 0;
for(int i = 0; i < heights.size(); i++)
{
total_area += heights[i] * widths[i];
}
std::cout << "total_area == " << total_area << "\n";
}