[Numpy-discussion] Tensor-Like Outer Product Question

Friedrich Romstedt friedrichromstedt at gmail.com
Tue Aug 3 16:42:07 EDT 2010


2010/8/3 matt_in_nyc <mkraning at 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.

Friedrich



More information about the NumPy-Discussion mailing list