[Numpy-discussion] Is this a bug in numpy.ma.reduce?

David Goldsmith d.l.goldsmith@gmail....
Mon Mar 8 13:57:03 CST 2010


How embarrassing! :O  Well, as they say, 'nother set of eyes...

Thanks!

DG

On Mon, Mar 8, 2010 at 11:25 AM, Friedrich Romstedt <
friedrichromstedt@gmail.com> wrote:

> It's pretty simple, but I was stunned myself how simple.  Have a look
> at line 65 of your script you provided:
>
> W = W.T
>
> This means,  x <-> y.  But in the for loops, you still act as if W
> wasn't transposed.  I added some prints, the positions should be clear
> for you:
>
> argW.shape = (320, 200)
> i, j = (0, 0)
> j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (0, 50, 0, 80)
> part2plot.shape = (50, 80)
> i, j = (0, 1)
> j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (50, 100, 0, 80)
> part2plot.shape = (50, 80)
> i, j = (0, 2)
> j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (100, 150, 0, 80)
> part2plot.shape = (50, 80)
> i, j = (0, 3)
> j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (150, 200, 0, 80)
> part2plot.shape = (50, 80)
> i, j = (1, 0)
> j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (0, 50, 80, 160)
> part2plot.shape = (50, 80)
> i, j = (1, 1)
> j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (50, 100, 80, 160)
> part2plot.shape = (50, 80)
> i, j = (1, 2)
> j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (100, 150, 80, 160)
> part2plot.shape = (50, 80)
> i, j = (1, 3)
> j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (150, 200, 80, 160)
> part2plot.shape = (50, 80)
> i, j = (2, 0)
> j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (0, 50, 160, 240)
> part2plot.shape = (50, 40)
> i, j = (2, 1)
> j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (50, 100, 160, 240)
> part2plot.shape = (50, 40)
> i, j = (2, 2)
> j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (100, 150, 160, 240)
> part2plot.shape = (50, 40)
> i, j = (2, 3)
> j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (150, 200, 160, 240)
> part2plot.shape = (50, 40)
> i, j = (3, 0)
> j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (0, 50, 240, 320)
> part2plot.shape = (50, 0)
> Traceback (most recent call last):
>   File "D:\Home\Friedrich\Entwicklung\2010\David\aquarius.py", line 91, in
> ?
>    ax.imshow(part2plot, extent = extent)
>  File
> "D:\Programme\Programmierung\python-2.4.1\lib\site-packages\matplotlib\ax
> es.py", line 5471, in imshow
>    im.autoscale_None()
>  File
> "D:\Programme\Programmierung\python-2.4.1\lib\site-packages\matplotlib\cm
> .py", line 148, in autoscale_None
>     self.norm.autoscale_None(self._A)
>   File
> "D:\Programme\Programmierung\python-2.4.1\lib\site-packages\matplotlib\co
> lors.py", line 682, in autoscale_None
>     if self.vmin is None: self.vmin = ma.minimum(A)
>   File
> "D:\Programme\Programmierung\python-2.4.1\lib\site-packages\numpy\ma\core
> .py", line 3042, in __call__
>    return self.reduce(a)
>  File
> "D:\Programme\Programmierung\python-2.4.1\lib\site-packages\numpy\ma\core
> .py", line 3057, in reduce
>     t = self.ufunc.reduce(target, **kargs)
> ValueError: zero-size array to ufunc.reduce without identity
>
> So you simply have to exchange the role of x and y in your slice
> indicing expression, and everything will work out fine, I suspect :-)
>
> Or simpy leave out the transposition?  Note that in the other case,
> you also may have to consider to change to extent's axes to get it
> properly reflected.
>
> NB: With my version of matplotlib, it didn't accept the colormap, but
> when yours does, it doesn't matter.
>
> Friedrich
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100308/4ccc7837/attachment-0001.html 


More information about the NumPy-Discussion mailing list