I have a 2d numpy array X = (xrows, xcols)
and I want to apply dot product on each row combination of the array to obtain another array which is of the shape P = (xrow, xrow)
.
The code looks like the following:
P = np.zeros((xrow, xrow))
for i in range(xrow):
for j in range(xrow):
P[i, j] = numpy.dot(X[i], X[j])
which works well if the array X
is small but takes a lot of time for huge X
. Is there any way to make it faster or do it more pythonically so that it is fast?