[Numpy-discussion] Matrix products

konrad.hinsen at laposte.net konrad.hinsen at laposte.net
Tue Jan 25 05:33:01 CST 2005


On Jan 25, 2005, at 14:10, Curzio Basso wrote:

> assume that I have a matrix A with shape = (m,n), what I would like to 
> compute is a matrix B with shape = (m, n, n) such as
> B[i] = NA.matrixmultiply(A[i, :, NA.NewAxis], A[i, NA.NewAxis])
...
> Does anyone know how to do this without using loops?

How about

	A[:, :, NewAxis]*A[:, NewAxis, :]

That works for your example at least. I am not quite sure why you use 
matrixmultiply in your definition as there doesn't seem to be any 
summation.

Konrad.
--
---------------------------------------------------------------------
Konrad Hinsen
Laboratoire Léon Brillouin, CEA Saclay,
91191 Gif-sur-Yvette Cedex, France
Tel.: +33-1 69 08 79 25
Fax: +33-1 69 08 82 61
E-Mail: hinsen at llb.saclay.cea.fr
---------------------------------------------------------------------





More information about the Numpy-discussion mailing list