[Numpy-discussion] Tensor-Like Outer Product Question

Friedrich Romstedt friedrichromstedt@gmail....
Tue Aug 3 15:42:07 CDT 2010

2010/8/3 matt_in_nyc <mkraning@gmail.com>:
> X is an m by n matrix, and I want to store outer products of the form Y[i] =
> numpy.outer(X[i,:], X[i,:]), leading to the relation Y[i,j,k] =
> X[i,j]*X[i,k] for i = 0,...,m-1; j,k = 0,...,n-1.  I am trying to think of
> how to do this using tensordot, but so far I am finding no inspiration.

What about:

X[:, :, numpy.newaxis] * X[:, numpy.newaxis, :]

? untested.


More information about the NumPy-Discussion mailing list