문제

programmers12949

행렬의 곱을 직접 구현해보는 문제
np.dot()을 감사하게 쓰자..

#include <string>
#include <vector>
using namespace std;

vector<vector<int>> solution(vector<vector<int>> arr1, vector<vector<int>> arr2) {
    vector<vector<int>> answer;

    int row1 = arr1.size();
    int col1 = arr1[0].size();
    int row2 = col1;
    int col2 = arr2[0].size();
    int i, j, k;

    // resize answer vector 
    answer.resize(row1);
    for(i = 0; i < row1; i++) answer[i].resize(col2);

    for(i = 0; i < row1; i++) {
        for(j = 0; j < col2; j++) {
            int tmp = 0;
            for(k = 0; k < col1; k++) tmp += arr1[i][k] * arr2[k][j];
            answer[i][j] = tmp;
        }
    }
    return answer;
}