兩個向量的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