[Numpy-discussion] Min Error
Sebastian Berg
sebastian at sipsolutions.net
Sun Sep 22 11:25:48 EDT 2013
On Sun, 2013-09-22 at 10:54 -0400, David Reed wrote:
> Sebastian,
>
>
> I apologize, that did work. I forgot to autoreload. Can you explain
> why the original code did work at the debug prompt?
>
Probably the debug prompt clears the errors or such. There was a bug (it
actually is already fixed in 1.8. but since it was part of a few larger
changes, it didn't get backported).
If you know the Python C-Api. In it, you set the error *and* return a
magic value (NULL or -1) to indicate that there may have been an error.
This is also commonly done in conversion functions.
The error got set, but the magic value did not get returned, making
everything continue as normal, *until* some other function gets a magic
value, which triggers:
if ((value == -1) && PyErr_Occurred())
because PyErr_Occurred returns something when it should not.
- Sebastian
>
> -Dave
>
>
> On Sun, Sep 22, 2013 at 10:45 AM, David Reed <david.reed.c at gmail.com>
> wrote:
> Thanks Sebastian, but still have same error. Also doesn't
> explain why it works when I run the same code at the debug
> prompt. Scratching my head on this one.
>
>
> Dave
>
>
> On Sun, Sep 22, 2013 at 10:42 AM, Sebastian Berg
> <sebastian at sipsolutions.net> wrote:
> On Sun, 2013-09-22 at 10:21 -0400, David Reed wrote:
> > Hi,
> >
> >
> > I am getting a strange error when finding the
> minimum of a matrix.
> > The weird thing is I get this while running within
> iPython shell, and
> > if I do %debug and go to the line where this fails
> and run the command
> > `a = np.min(D, axis=0)`, I get no error.
> >
> >
> > Here is the trace:
> >
> >
> > draw_lines/main.pyc in haus_distance(A, B)
> > 28 D = D.reshape((len(A), None))
> > 29
> > ---> 30 a = np.min(D, axis=0)
> > 31
> > 32 # vp = np.max(np.min(D, axis=0))
> >
>
>
> There is an error in the reshape code. The real error
> is the None in
> your reshape right above, it should be -1.
> This is not surfaced correctly due to a bug in
> Reshape, but instead gets
> surfaced (somewhat randomly) lateron.
>
> - Sebastian
>
> >
> >
> anaconda/lib/python2.7/site-packages/numpy/core/fromnumeric.pyc in
> > amin(a, axis, out, keepdims)
> > 1985 else:
> > 1986 return _methods._amin(a, axis=axis,
> > -> 1987 out=out,
> keepdims=keepdims)
> > 1988
> > 1989 def alen(a):
> >
> >
> >
> anaconda/lib/python2.7/site-packages/numpy/core/_methods.pyc in
> > _amin(a, axis, out, keepdims)
> > 12 def _amin(a, axis=None, out=None,
> keepdims=False):
> > 13 return um.minimum.reduce(a, axis=axis,
> > ---> 14 out=out,
> keepdims=keepdims)
> > 15
> > 16 def _sum(a, axis=None, dtype=None, out=None,
> keepdims=False):
> >
> >
> > TypeError: an integer is required
> >
> >
> >
> >
>
> > _______________________________________________
> > NumPy-Discussion mailing list
> > NumPy-Discussion at scipy.org
> >
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
More information about the NumPy-Discussion
mailing list