两个向量的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);
    }
}

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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM