Is this a bug in numpy.ma.reduce?
Hi! Sorry for the cross-post, but my own investigation has led me to suspect that mine is actually a numpy problem, not a matplotlib problem. I'm getting the following traceback from a call to matplotlib.imshow: Traceback (most recent call last): File "C:\Users\Fermat\Documents\Fractals\Python\Source\Zodiac\aquarius_test.py", line 108, in <module> ax.imshow(part2plot, cmap_name, extent = extent) File "C:\Python254\lib\site-packages\matplotlib\axes.py", line 6261, in imshow im.autoscale_None() File "C:\Python254\lib\site-packages\matplotlib\cm.py", line 236, in autoscale_None self.norm.autoscale_None(self._A) File "C:\Python254\lib\site-packages\matplotlib\colors.py", line 792, in autoscale_None if self.vmin is None: self.vmin = ma.minimum(A) File "C:\Python254\Lib\site-packages\numpy\ma\core.py", line 5555, in __call__ return self.reduce(a) File "C:\Python254\Lib\site-packages\numpy\ma\core.py", line 5570, in reduce t = self.ufunc.reduce(target, **kargs) ValueError: zero-size array to ufunc.reduce without identity Script terminated. Based on examination of the code, the last self is an instance of ma._extrema_operation (or one of its subclasses) - is there a reason why this class is unable to deal with a "zero-size array to ufunc.reduce without identity," (i.e., was it thought that it would - or should - never get one) or was this merely an oversight? Either way, there's other instances on the lists of this error cropping up, so this circumstance should probably be handled more robustly. In the meantime, workaround? DG
On Mar 5, 2010, at 4:38 AM, David Goldsmith wrote:
Hi! Sorry for the cross-post, but my own investigation has led me to suspect that mine is actually a numpy problem, not a matplotlib problem. I'm getting the following traceback from a call to matplotlib.imshow: ... Based on examination of the code, the last self is an instance of ma._extrema_operation (or one of its subclasses) - is there a reason why this class is unable to deal with a "zero-size array to ufunc.reduce without identity," (i.e., was it thought that it would - or should - never get one) or was this merely an oversight? Either way, there's other instances on the lists of this error cropping up, so this circumstance should probably be handled more robustly. In the meantime, workaround?
'm'fraid no. I gonna have to investigate that. Please open a ticket with a self-contained example that reproduces the issue. Thx in advance... P.
On 03/05/2010 11:51 AM, Pierre GM wrote:
On Mar 5, 2010, at 4:38 AM, David Goldsmith wrote:
Hi! Sorry for the cross-post, but my own investigation has led me to suspect that mine is actually a numpy problem, not a matplotlib problem. I'm getting the following traceback from a call to matplotlib.imshow: ... Based on examination of the code, the last self is an instance of ma._extrema_operation (or one of its subclasses) - is there a reason why this class is unable to deal with a "zero-size array to ufunc.reduce without identity," (i.e., was it thought that it would - or should - never get one) or was this merely an oversight? Either way, there's other instances on the lists of this error cropping up, so this circumstance should probably be handled more robustly. In the meantime, workaround?
'm'fraid no. I gonna have to investigate that. Please open a ticket with a self-contained example that reproduces the issue. Thx in advance... P.
This might be completely wrong, but I seem to remember a similar issue, which I then traced down to having a masked array with a mask that was set to True or False, instead of being a full fledged bool mask array. I was in a hurry then and completely forgot about it later, so filed no bug report whatsoever, for which I apologize. VS.
On Fri, Mar 5, 2010 at 2:51 AM, Pierre GM <pgmdevlist@gmail.com> wrote:
Hi! Sorry for the cross-post, but my own investigation has led me to suspect that mine is actually a numpy problem, not a matplotlib problem. I'm getting the following traceback from a call to matplotlib.imshow: ... Based on examination of the code, the last self is an instance of ma._extrema_operation (or one of its subclasses) - is there a reason why
On Mar 5, 2010, at 4:38 AM, David Goldsmith wrote: this class is unable to deal with a "zero-size array to ufunc.reduce without identity," (i.e., was it thought that it would - or should - never get one) or was this merely an oversight? Either way, there's other instances on the lists of this error cropping up, so this circumstance should probably be handled more robustly. In the meantime, workaround?
'm'fraid no. I gonna have to investigate that. Please open a ticket with a self-contained example that reproduces the issue.
I'll do my best, but since it's a call from matplotlib and I don't really know what's causing the problem (other than a literal reading of the exception) I'm not sure I can. DG
Thx in advance... P. _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
On Fri, Mar 5, 2010 at 9:22 AM, David Goldsmith <d.l.goldsmith@gmail.com>wrote:
On Fri, Mar 5, 2010 at 2:51 AM, Pierre GM <pgmdevlist@gmail.com> wrote:
Hi! Sorry for the cross-post, but my own investigation has led me to suspect that mine is actually a numpy problem, not a matplotlib problem. I'm getting the following traceback from a call to matplotlib.imshow: ... Based on examination of the code, the last self is an instance of ma._extrema_operation (or one of its subclasses) - is there a reason why
On Mar 5, 2010, at 4:38 AM, David Goldsmith wrote: this class is unable to deal with a "zero-size array to ufunc.reduce without identity," (i.e., was it thought that it would - or should - never get one) or was this merely an oversight? Either way, there's other instances on the lists of this error cropping up, so this circumstance should probably be handled more robustly. In the meantime, workaround?
'm'fraid no. I gonna have to investigate that. Please open a ticket with a self-contained example that reproduces the issue.
I'll do my best, but since it's a call from matplotlib and I don't really know what's causing the problem (other than a literal reading of the exception) I'm not sure I can.
Well, that was easy: mn = N.ma.core._minimum_operation() mn.reduce(N.array(())) Traceback (most recent call last): File "<input>", line 1, in <module> File "C:\Python254\Lib\site-packages\numpy\ma\core.py", line 5570, in reduce t = self.ufunc.reduce(target, **kargs) ValueError: zero-size array to ufunc.reduce without identity I'll file a ticket. DG
DG
Thx in advance... P. _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
On Fri, Mar 5, 2010 at 9:43 AM, David Goldsmith <d.l.goldsmith@gmail.com>wrote:
On Fri, Mar 5, 2010 at 9:22 AM, David Goldsmith <d.l.goldsmith@gmail.com>wrote:
On Fri, Mar 5, 2010 at 2:51 AM, Pierre GM <pgmdevlist@gmail.com> wrote:
Hi! Sorry for the cross-post, but my own investigation has led me to suspect that mine is actually a numpy problem, not a matplotlib problem. I'm getting the following traceback from a call to matplotlib.imshow: ... Based on examination of the code, the last self is an instance of ma._extrema_operation (or one of its subclasses) - is there a reason why
On Mar 5, 2010, at 4:38 AM, David Goldsmith wrote: this class is unable to deal with a "zero-size array to ufunc.reduce without identity," (i.e., was it thought that it would - or should - never get one) or was this merely an oversight? Either way, there's other instances on the lists of this error cropping up, so this circumstance should probably be handled more robustly. In the meantime, workaround?
'm'fraid no. I gonna have to investigate that. Please open a ticket with a self-contained example that reproduces the issue.
I'll do my best, but since it's a call from matplotlib and I don't really know what's causing the problem (other than a literal reading of the exception) I'm not sure I can.
Well, that was easy:
mn = N.ma.core._minimum_operation() mn.reduce(N.array(()))
Traceback (most recent call last): File "<input>", line 1, in <module>
File "C:\Python254\Lib\site-packages\numpy\ma\core.py", line 5570, in reduce t = self.ufunc.reduce(target, **kargs) ValueError: zero-size array to ufunc.reduce without identity
I'll file a ticket.
OK, Ticket #1422 filed. DG
2010/3/5 Pierre GM <pgmdevlist@gmail.com>:
'm'fraid no. I gonna have to investigate that. Please open a ticket with a self-contained example that reproduces the issue. Thx in advance... P.
I would like to stress the fact that imo this is maybe not ticket and not a bug. The issue arises when calling a.max() or similar of empty arrays a, i.e., with:
0 in a.shape True
Opposed to the .prod() of an empty array, such a .max() or .min() cannot be defined, because the set is empty. So it's fully correct to let such calls fail. Just the failure is a bit deep in numpy, and only the traceback gives some hint what went wrong. I posted something similar also on the matplotlib-users list, sorry for cross-posting thus. fwiw, Friedrich
On Sun, Mar 7, 2010 at 4:41 AM, Friedrich Romstedt < friedrichromstedt@gmail.com> wrote:
2010/3/5 Pierre GM <pgmdevlist@gmail.com>:
'm'fraid no. I gonna have to investigate that. Please open a ticket with a self-contained example that reproduces the issue. Thx in advance... P.
I would like to stress the fact that imo this is maybe not ticket and not a bug.
The issue arises when calling a.max() or similar of empty arrays a, i.e., with:
0 in a.shape True
Opposed to the .prod() of an empty array, such a .max() or .min() cannot be defined, because the set is empty. So it's fully correct to let such calls fail. Just the failure is a bit deep in numpy, and only the traceback gives some hint what went wrong.
I posted something similar also on the matplotlib-users list, sorry for cross-posting thus.
Any suggestions, then, how to go about figuring out what's happening in my code that's causing this "feature" to manifest itself? DG
fwiw, Friedrich _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
On 03/08/2010 01:30 AM, David Goldsmith wrote:
On Sun, Mar 7, 2010 at 4:41 AM, Friedrich Romstedt <friedrichromstedt@gmail.com <mailto:friedrichromstedt@gmail.com>> wrote:
2010/3/5 Pierre GM <pgmdevlist@gmail.com <mailto:pgmdevlist@gmail.com>>: > 'm'fraid no. I gonna have to investigate that. Please open a ticket with a self-contained example that reproduces the issue. > Thx in advance... > P.
I would like to stress the fact that imo this is maybe not ticket and not a bug.
The issue arises when calling a.max() or similar of empty arrays a, i.e., with:
>>> 0 in a.shape True
Opposed to the .prod() of an empty array, such a .max() or .min() cannot be defined, because the set is empty. So it's fully correct to let such calls fail. Just the failure is a bit deep in numpy, and only the traceback gives some hint what went wrong.
I posted something similar also on the matplotlib-users list, sorry for cross-posting thus.
Any suggestions, then, how to go about figuring out what's happening in my code that's causing this "feature" to manifest itself?
DG
Perhaps providing the code with specific versions of Python, numpy etc. would help. I would guess that aquarius_test.py has not correctly setup the necessary inputs (or has invalid inputs) required by matplotlib (which I have no knowledge about). Really you have to find if the _A in cmp.py used by 'self.norm.autoscale_None(self._A)' is valid. You may be missing a valid initialization step because the TypeError exception in autoscale_None ('You must first set_array for mappable') implies something need to be done first. Bruce
On Mon, Mar 8, 2010 at 6:52 AM, Bruce Southey <bsouthey@gmail.com> wrote:
On 03/08/2010 01:30 AM, David Goldsmith wrote:
On Sun, Mar 7, 2010 at 4:41 AM, Friedrich Romstedt < friedrichromstedt@gmail.com> wrote:
I would like to stress the fact that imo this is maybe not ticket and not a bug.
The issue arises when calling a.max() or similar of empty arrays a, i.e., with:
0 in a.shape True
Opposed to the .prod() of an empty array, such a .max() or .min() cannot be defined, because the set is empty. So it's fully correct to let such calls fail. Just the failure is a bit deep in numpy, and only the traceback gives some hint what went wrong.
I posted something similar also on the matplotlib-users list, sorry for cross-posting thus.
Any suggestions, then, how to go about figuring out what's happening in my code that's causing this "feature" to manifest itself?
DG
Perhaps providing the code with specific versions of Python, numpy etc. would help.
I would guess that aquarius_test.py has not correctly setup the necessary inputs (or has invalid inputs) required by matplotlib (which I have no knowledge about). Really you have to find if the _A in cmp.py used by 'self.norm.autoscale_None(self._A)' is valid. You may be missing a valid initialization step because the TypeError exception in autoscale_None ('You must first set_array for mappable') implies something need to be done first.
Bruce
Python 2.5.4, Numpy 1.4.0, Matplotlib 0.99.0, Windows 32bit Vista Home Premium SP2 # Code copyright 2010 by David Goldsmith # Comments and unnecessaries edited for brevity import numpy as N import matplotlib as MPL from matplotlib import pylab from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure import matplotlib.cm as cm J = complex(0,1); tol = 1e-6; maxiter = 20; roots = (-2 + J/2, -1 + J, -0.5 + J/2, 0.5 + J, 1 + J/2, 2 + J, 2.5 + J/2, -2 - J, -1 - J/2, -0.5 - J, 0.5 - J/2, 1 - J, 2 - J/2, 2.5 - J) def ffp(z): w, wp = (0J, 0J) for root in roots: z0 = z - root w += N.sin(1/z0) wp -= N.cos(1/z0)/(z0*z0) return (w, wp) def iter(z): w, wp = ffp(z) return z - w/wp def find_root(z0):#, k, j): count = 0 z1 = iter(z0) if N.isnan(z1): return N.complex64(N.inf) while (N.abs(z1 - z0) > tol) and \ (count < maxiter): count += 1 z0 = z1 z1 = iter(z0) if N.abs(z1 - z0) > tol: result = 0 else: result = z1 return N.complex64(result) w, h, DPI = (3.2, 2.0, 100) fig = Figure(figsize=(w, h), dpi=DPI, frameon=False) ax = fig.add_subplot(1,1,1) canvas = FigureCanvas(fig) nx, xmin, xmax = (int(w*DPI), -0.5, 0.5) ny, ymin, ymax = (int(h*DPI), 0.6, 1.2) X, xincr = N.linspace(xmin,xmax,nx,retstep=True) Y, yincr = N.linspace(ymin,ymax,ny,retstep=True) W = N.zeros((ny,nx), dtype=N.complex64) for j in N.arange(nx): if not (j%100): # report progress print j for k in N.arange(ny): x, y = (X[j], Y[k]) z0 = x + J*y W[k,j] = find_root(z0)#,k,j) print N.argwhere(N.logical_not(N.isfinite(W.real))) print N.argwhere(N.logical_not(N.isfinite(W.imag))) W = W.T argW = N.angle(W) print N.argwhere(N.logical_not(N.isfinite(argW))) cms = ("Blues",)# "Blues_r", "cool", "cool_r", def all_ticks_off(ax): ax.xaxis.set_major_locator(pylab.NullLocator()) ax.yaxis.set_major_locator(pylab.NullLocator()) for cmap_name in cms: all_ticks_off(ax) ax.hold(True) for i in range(4): for j in range(4): part2plot = argW[j*ny/4:(j+1)*ny/4, i*nx/4:(i+1)*nx/4] if N.any(N.logical_not(N.isfinite(part2plot))): print i, j, print N.argwhere(N.logical_not(N.isfinite(part2plot))) extent = (i*nx/4, (i+1)*nx/4, (j+1)*ny/4, j*ny/4) ax.imshow(part2plot, cmap_name, extent = extent) ax.set_xlim(0, nx) ax.set_ylim(0, ny) canvas.print_figure('../../Data-Figures/Zodiac/Aquarius/'+ cmap_name + 'Aquarius_test.png', dpi=DPI) # End Aquarius_test.png DG
On Mon, Mar 8, 2010 at 10:17 AM, David Goldsmith <d.l.goldsmith@gmail.com>wrote:
On Mon, Mar 8, 2010 at 6:52 AM, Bruce Southey <bsouthey@gmail.com> wrote:
On 03/08/2010 01:30 AM, David Goldsmith wrote:
On Sun, Mar 7, 2010 at 4:41 AM, Friedrich Romstedt < friedrichromstedt@gmail.com> wrote:
I would like to stress the fact that imo this is maybe not ticket and not a bug.
The issue arises when calling a.max() or similar of empty arrays a, i.e., with:
0 in a.shape True
Opposed to the .prod() of an empty array, such a .max() or .min() cannot be defined, because the set is empty. So it's fully correct to let such calls fail. Just the failure is a bit deep in numpy, and only the traceback gives some hint what went wrong.
I posted something similar also on the matplotlib-users list, sorry for cross-posting thus.
Any suggestions, then, how to go about figuring out what's happening in my code that's causing this "feature" to manifest itself?
DG
Perhaps providing the code with specific versions of Python, numpy etc. would help.
I would guess that aquarius_test.py has not correctly setup the necessary inputs (or has invalid inputs) required by matplotlib (which I have no knowledge about). Really you have to find if the _A in cmp.py used by 'self.norm.autoscale_None(self._A)' is valid. You may be missing a valid initialization step because the TypeError exception in autoscale_None ('You must first set_array for mappable') implies something need to be done first.
Bruce
Python 2.5.4, Numpy 1.4.0, Matplotlib 0.99.0, Windows 32bit Vista Home Premium SP2
# Code copyright 2010 by David Goldsmith # Comments and unnecessaries edited for brevity import numpy as N import matplotlib as MPL from matplotlib import pylab from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure import matplotlib.cm as cm
J = complex(0,1); tol = 1e-6; maxiter = 20; roots = (-2 + J/2, -1 + J, -0.5 + J/2, 0.5 + J, 1 + J/2, 2 + J, 2.5 + J/2, -2 - J, -1 - J/2, -0.5 - J, 0.5 - J/2, 1 - J, 2 - J/2, 2.5 - J)
def ffp(z): w, wp = (0J, 0J) for root in roots: z0 = z - root w += N.sin(1/z0) wp -= N.cos(1/z0)/(z0*z0) return (w, wp)
def iter(z): w, wp = ffp(z) return z - w/wp
def find_root(z0):#, k, j): count = 0 z1 = iter(z0) if N.isnan(z1): return N.complex64(N.inf) while (N.abs(z1 - z0) > tol) and \ (count < maxiter): count += 1 z0 = z1 z1 = iter(z0) if N.abs(z1 - z0) > tol: result = 0 else: result = z1 return N.complex64(result)
w, h, DPI = (3.2, 2.0, 100) fig = Figure(figsize=(w, h), dpi=DPI, frameon=False) ax = fig.add_subplot(1,1,1) canvas = FigureCanvas(fig) nx, xmin, xmax = (int(w*DPI), -0.5, 0.5) ny, ymin, ymax = (int(h*DPI), 0.6, 1.2)
X, xincr = N.linspace(xmin,xmax,nx,retstep=True) Y, yincr = N.linspace(ymin,ymax,ny,retstep=True) W = N.zeros((ny,nx), dtype=N.complex64)
for j in N.arange(nx): if not (j%100): # report progress print j for k in N.arange(ny): x, y = (X[j], Y[k]) z0 = x + J*y W[k,j] = find_root(z0)#,k,j)
print N.argwhere(N.logical_not(N.isfinite(W.real))) print N.argwhere(N.logical_not(N.isfinite(W.imag))) W = W.T argW = N.angle(W) print N.argwhere(N.logical_not(N.isfinite(argW))) cms = ("Blues",)# "Blues_r", "cool", "cool_r",
def all_ticks_off(ax): ax.xaxis.set_major_locator(pylab.NullLocator()) ax.yaxis.set_major_locator(pylab.NullLocator())
for cmap_name in cms: all_ticks_off(ax) ax.hold(True) for i in range(4): for j in range(4): part2plot = argW[j*ny/4:(j+1)*ny/4, i*nx/4:(i+1)*nx/4] if N.any(N.logical_not(N.isfinite(part2plot))): print i, j, print N.argwhere(N.logical_not(N.isfinite(part2plot))) extent = (i*nx/4, (i+1)*nx/4, (j+1)*ny/4, j*ny/4)
ax.imshow(part2plot, cmap_name, extent = extent) ax.set_xlim(0, nx) ax.set_ylim(0, ny) canvas.print_figure('../../Data-Figures/Zodiac/Aquarius/'+ cmap_name + 'Aquarius_test.png', dpi=DPI) # End Aquarius_test.png
DG
Oh, and here's "fresh" output (i.e., I just reran it to confirm that I'm still having the problem). 0 100 200 300 [[133 319]] [] [] Traceback (most recent call last): File "C:\Users\Fermat\Documents\Fractals\Python\Source\Zodiac\aquarius_test.py", line 108, in <module> ax.imshow(part2plot, cmap_name, extent = extent) File "C:\Python254\lib\site-packages\matplotlib\axes.py", line 6261, in imshow im.autoscale_None() File "C:\Python254\lib\site-packages\matplotlib\cm.py", line 236, in autoscale_None self.norm.autoscale_None(self._A) File "C:\Python254\lib\site-packages\matplotlib\colors.py", line 792, in autoscale_None if self.vmin is None: self.vmin = ma.minimum(A) File "C:\Python254\Lib\site-packages\numpy\ma\core.py", line 5555, in __call__ return self.reduce(a) File "C:\Python254\Lib\site-packages\numpy\ma\core.py", line 5570, in reduce t = self.ufunc.reduce(target, **kargs) ValueError: zero-size array to ufunc.reduce without identity Script terminated. Notes: 0) Despite N.argwhere(N.logical_not(N.isfinite(W.real))) being non-empty, N.argwhere(N.logical_not(N.isfinite(N.angle(W.T)))) apparently is empty, so I suppose whatever is behind this may also be the source of my problem, but: 1) Nothing is ever printed as a result of this attempt to catch a non-finite problem: if N.any(N.logical_not(N.isfinite(part2plot))): print i, j, print N.argwhere(N.logical_not(N.isfinite(part2plot))) which occurs for all part2plot's before they're passed to imshow, so I conclude that the problem is something other than non-finites? DG
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
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
On 03/08/2010 12:17 PM, David Goldsmith wrote:
On Mon, Mar 8, 2010 at 6:52 AM, Bruce Southey <bsouthey@gmail.com <mailto:bsouthey@gmail.com>> wrote:
On 03/08/2010 01:30 AM, David Goldsmith wrote:
On Sun, Mar 7, 2010 at 4:41 AM, Friedrich Romstedt <friedrichromstedt@gmail.com <mailto:friedrichromstedt@gmail.com>> wrote:
I would like to stress the fact that imo this is maybe not ticket and not a bug.
The issue arises when calling a.max() or similar of empty arrays a, i.e., with:
>>> 0 in a.shape True
Opposed to the .prod() of an empty array, such a .max() or .min() cannot be defined, because the set is empty. So it's fully correct to let such calls fail. Just the failure is a bit deep in numpy, and only the traceback gives some hint what went wrong.
I posted something similar also on the matplotlib-users list, sorry for cross-posting thus.
Any suggestions, then, how to go about figuring out what's happening in my code that's causing this "feature" to manifest itself?
DG
Perhaps providing the code with specific versions of Python, numpy etc. would help.
I would guess that aquarius_test.py has not correctly setup the necessary inputs (or has invalid inputs) required by matplotlib (which I have no knowledge about). Really you have to find if the _A in cmp.py used by 'self.norm.autoscale_None(self._A)' is valid. You may be missing a valid initialization step because the TypeError exception in autoscale_None ('You must first set_array for mappable') implies something need to be done first.
Bruce
Python 2.5.4, Numpy 1.4.0, Matplotlib 0.99.0, Windows 32bit Vista Home Premium SP2
# Code copyright 2010 by David Goldsmith # Comments and unnecessaries edited for brevity import numpy as N import matplotlib as MPL from matplotlib import pylab from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure import matplotlib.cm <http://matplotlib.cm> as cm
J = complex(0,1); tol = 1e-6; maxiter = 20; roots = (-2 + J/2, -1 + J, -0.5 + J/2, 0.5 + J, 1 + J/2, 2 + J, 2.5 + J/2, -2 - J, -1 - J/2, -0.5 - J, 0.5 - J/2, 1 - J, 2 - J/2, 2.5 - J)
def ffp(z): w, wp = (0J, 0J) for root in roots: z0 = z - root w += N.sin(1/z0) wp -= N.cos(1/z0)/(z0*z0) return (w, wp)
def iter(z): w, wp = ffp(z) return z - w/wp
def find_root(z0):#, k, j): count = 0 z1 = iter(z0) if N.isnan(z1): return N.complex64(N.inf) while (N.abs(z1 - z0) > tol) and \ (count < maxiter): count += 1 z0 = z1 z1 = iter(z0) if N.abs(z1 - z0) > tol: result = 0 else: result = z1 return N.complex64(result)
w, h, DPI = (3.2, 2.0, 100) fig = Figure(figsize=(w, h), dpi=DPI, frameon=False) ax = fig.add_subplot(1,1,1) canvas = FigureCanvas(fig) nx, xmin, xmax = (int(w*DPI), -0.5, 0.5) ny, ymin, ymax = (int(h*DPI), 0.6, 1.2)
X, xincr = N.linspace(xmin,xmax,nx,retstep=True) Y, yincr = N.linspace(ymin,ymax,ny,retstep=True) W = N.zeros((ny,nx), dtype=N.complex64)
for j in N.arange(nx): if not (j%100): # report progress print j for k in N.arange(ny): x, y = (X[j], Y[k]) z0 = x + J*y W[k,j] = find_root(z0)#,k,j)
print N.argwhere(N.logical_not(N.isfinite(W.real))) print N.argwhere(N.logical_not(N.isfinite(W.imag))) W = W.T argW = N.angle(W) print N.argwhere(N.logical_not(N.isfinite(argW))) cms = ("Blues",)# "Blues_r", "cool", "cool_r",
def all_ticks_off(ax): ax.xaxis.set_major_locator(pylab.NullLocator()) ax.yaxis.set_major_locator(pylab.NullLocator())
for cmap_name in cms: all_ticks_off(ax) ax.hold(True) for i in range(4): for j in range(4): part2plot = argW[j*ny/4:(j+1)*ny/4, i*nx/4:(i+1)*nx/4] if N.any(N.logical_not(N.isfinite(part2plot))): print i, j, print N.argwhere(N.logical_not(N.isfinite(part2plot))) extent = (i*nx/4, (i+1)*nx/4, (j+1)*ny/4, j*ny/4) ax.imshow(part2plot, cmap_name, extent = extent) ax.set_xlim(0, nx) ax.set_ylim(0, ny) canvas.print_figure('../../Data-Figures/Zodiac/Aquarius/'+ cmap_name + 'Aquarius_test.png', dpi=DPI) # End Aquarius_test.png
DG
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Hmm, Appears that you have mixed your indices when creating part2plot. If you this line instead it works: part2plot = argW[j*nx/4:(j+1)*nx/4, i*ny/4:(i+1)*ny/4] I found that by looking the shape of the part2plot array that is component of the argW array. The shape of argW is (320, 200). So in your loops to find part2plot you eventually exceed 200 and eventually the index to the second axis is greater than 200 causing everything to crash: When i=0 or 1 then the shape of part2plot is (50, 80) when i=2 then the shape of part2plot is (50, 40) when i=3 then the shape of part2plot is (50, 0) # crash Bruce
2010/3/8 Bruce Southey <bsouthey@gmail.com>:
Hmm, Appears that you have mixed your indices when creating part2plot. If you this line instead it works: part2plot = argW[j*nx/4:(j+1)*nx/4, i*ny/4:(i+1)*ny/4]
I found that by looking the shape of the part2plot array that is component of the argW array.
The shape of argW is (320, 200). So in your loops to find part2plot you eventually exceed 200 and eventually the index to the second axis is greater than 200 causing everything to crash: When i=0 or 1 then the shape of part2plot is (50, 80) when i=2 then the shape of part2plot is (50, 40) when i=3 then the shape of part2plot is (50, 0) # crash
Nice that we have found this out both at the same instance of time (with 5min precision) :-) Friedrich
participants (5)
-
Bruce Southey -
David Goldsmith -
Friedrich Romstedt -
Pierre GM -
Vincent Schut