[Tutor] calculation with arrays: shape mismatch

Alan Gauld alan.gauld at btinternet.com
Tue Oct 30 00:24:28 CET 2007

"John" <washakie at gmail.com> wrote

> Sorry, here's the output from the command line
>>>>run Day_footprint.py

Sorry for all the questions but I've never seen that "run" syntax 
What environment are you running? What IDE/OS/Python version etc?

> trying...
> header has been opened
> succes!
> Reading grid 20060511000000 at: Mon Oct 29 16:57:57 2007
> processing: 20060511000000
> Traceback (most recent call last):
>  File "Day_footprint.py", line 48, in ?
>    contribution=[contribution+grid[:,:,z:,k,0]/A for z in
> range(len(H['outheigh
> t']))]
> ValueError: shape mismatch: objects cannot be broadcast to a single 
> shape

Hmm, in this case the error isn't telli8ng us too much extra other
than the line it doesn't like. But, putting this together with the
code you posted earlier...

 for k in range(nr):
                           for z in range(len(H['outheight']))]

I will hazard a guess that N.zeros(...) is a different size to 

But since I have no idea what these look like - I assume its numPy
or somesuch structure ? - I can only guess. Can you decompose
the list comprehension and add some useful print statements
to help debug it?


Alan G. 

More information about the Tutor mailing list