0

I would like to find the dot-product between the first column of one 2D array (n x k) and all columns of another (dimensionally the same: n x k) 2D array, and repeat this for all columns of the first array, saving the results in a third 2D array (n x n). This task is not difficult to do with loops, however, to improve computation time I was wondering if it where possible to do this only with matrix multiplication.

Any help is much appreciated!

1 Answers1

0

By naming the matrices matrix_1, matrix_2 and matrix_3

matrix_3 = [[sum(a * b for a, b in zip(X_row, Y_col)) for Y_col in zip(*matrix_2)] for X_row in matrix_1 ]

or if efficiency is all you are looking for:

import Numpy as np

np.dot(matrix_1, matrix_2)