numpy : efficient sum computations

TG girodt at gmail.com
Tue Oct 16 07:38:19 EDT 2007


Okay, another one which I don't have answer for.

it is the reverse case, sort of :

> phi.shape (x,y)
> d.shape (a,b)

I want to return m :
> m.shape = (x,y,a,b)
with
m[x,y] = d * phi[x,y]

currently, my code is :
> m = empty(phi.shape + d.shape)
> m[:,:] = d

this repeats the matrix d x*y times, which is what I want. But now, if
I do :
> m[:,:] = d * phi[:,:]
in order to multiply each "d" by a specific value of "phi", it doesn't
work.

<type 'exceptions.ValueError'>: shape mismatch: objects cannot be
broadcast to a single shape

Right now I'm stuck here. If anyone can help, I would be glad.




More information about the Python-list mailing list