[Numpy-discussion] Compute multiple outer products without a loop?

Charles R Harris charlesr.harris@gmail....
Mon Feb 16 17:16:03 CST 2009


On Mon, Feb 16, 2009 at 4:06 PM, Ken Basye <kbasye1@jhu.edu> wrote:

> Hi List,
>   I need to compute multiple outer products from 2-d data in the
> following way:
> Given a and b with shape, e.g,  (10, 4), compute the 10 outer products
> of shape (4, 4) and get them into an array of shape (10, 4, 4).
> Currently I do this with a loop, but I'd really like some way to do it
> without looping.  I read that outer(a, b) is just syntactic sugar for
> a.ravel()[:, newaxis] * b.ravel()[newaxis,:] but unfortunately this
> didn't give me any bright ideas :->.
>   Thanks,
>       Ken
>

I think you can do what you want with newaxis and broadcasting, but I'm not
sure what you want ;) Could you post your current code and a small example?

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20090216/79a54aff/attachment.html 


More information about the Numpy-discussion mailing list