From your description, and almost no thinking:
Z=np.einsum('nk,nq->kq',X,Y)
I could also write it with np.dot
, with a transpose or two. np.dot
does the matrix sum over the last dim of the 1st and 2nd to last of 2nd
Z = np.dot(X.T, Y)
=================
In [566]: n,k,q=2,3,4
In [567]: X=np.arange(n*k).reshape(n,k)
In [568]: Y=np.arange(n*q).reshape(n,q)
In [569]: Z=np.einsum('nk,nq->kq',X,Y)
In [570]: Z
Out[570]:
array([[12, 15, 18, 21],
[16, 21, 26, 31],
[20, 27, 34, 41]])
In [571]: Z1=np.empty((k,q))
In [572]: Z1=np.array([X[:,c].dot(Y) for c in range(k)])
In [573]: Z1
Out[573]:
array([[12, 15, 18, 21],
[16, 21, 26, 31],
[20, 27, 34, 41]])
In [574]: X.T.dot(Y)
Out[574]:
array([[12, 15, 18, 21],
[16, 21, 26, 31],
[20, 27, 34, 41]])