Is this what you are looking for?
x = np.array([[1,2], [3,4]]) y = np.array([[5,6], [7,8]]) x[:,:,np.newaxis] * y[:,np.newaxis,:] array([[[ 5, 6], [10, 12]], [[21, 24], [28, 32]]])
EDIT:
Btw, itβs always useful to look at the implementation. Helps to understand "magic." np.outer looks like this:
return a.ravel()[:,newaxis]*b.ravel()[newaxis,:]
Itβs easy from here.
In addition, in your question you have:
[np.outer(x[i],y[i]) for i in xrange(x.shape[0])]
Better written as:
[np.outer(xx,yy) for xx,yy in izip(x,y)]
shx2 source share