两个向量的outer product

#include <functional>

template <class T1, class T2, class T3>
void outer_product(std::vector<T1> &inst1, std::vector<T2> &inst2, std::vector<std::vector<T3> > &out) {
    std::vector<T3> temp_row(inst2.size());

    for(typename::std::vector<T1>::const_iterator it=inst1.begin();it!=inst1.end();++it) {
        transform(inst2.begin(), inst2.end(), temp_row.begin(), bind2nd(std::multiplies<T1>(), *it));
        out.push_back(temp_row);
    }
}

列向量与行向量相乘,结果为一个二维矩阵。

posted @ 2018-08-29 14:50  东宫得臣  阅读(3142)  评论(0编辑  收藏  举报