[Numpy-discussion] Numpy performance vs Matlab.

Christopher Barker Chris.Barker@noaa....
Fri Jan 9 13:13:36 CST 2009


Nicolas ROUX wrote:
> -2- Now with the code below I have strange result.
> With w=h=400:

> With w=400 and h=300:
>    - Using "numpy.ogrid", => broadcast ERROR !
>  
> The last broadcast error is:
>  "ValueError: shape mismatch: objects cannot be broadcast to a single shape"

This is probably a broadcasting error, which means your result with w=h 
is probably wrong.

My advice:

Always test with non-square arrays, to make sure you are broadcasting as 
you expect.

Don't test with "zeros" or "ones" for your test data -- so you can look 
at the results and see if you are getting what you expect. I often use 
something like:

a = numpy.arange(w*h).reshape((h,w))

I also test with very small dimensions so that I can easily print the 
results of each step as I develop the code

With this approach you will probably figure out what's going on.

-Chris



-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker@noaa.gov


More information about the Numpy-discussion mailing list