[Numpy-discussion] how can one catch a multiarray.error

Charles R Harris charlesr.harris@gmail....
Mon Jun 1 22:06:05 CDT 2009


On Mon, Jun 1, 2009 at 8:37 PM, <josef.pktd@gmail.com> wrote:

> how do we catch a multiarray.error in a try except clause?
>
> e.g.
> >>> np.argmin([])
> Traceback (most recent call last):
>  File "<pyshell#147>", line 1, in <module>
>    np.argmin([])
>  File "C:\Programs\Python25\Lib\site-packages\numpy\core\fromnumeric.py",
> line 631, in argmin
>    return _wrapit(a, 'argmin', axis)
>  File "C:\Programs\Python25\Lib\site-packages\numpy\core\fromnumeric.py",
> line 37, in _wrapit
>    result = getattr(asarray(obj),method)(*args, **kwds)
> multiarray.error: attempt to get argmax/argmin of an empty sequence
>

What numpy version are you using? A ValueError is raised in recent versions:

In [1]: np.argmin([])
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)

/home/charris/<ipython console> in <module>()

/usr/lib/python2.5/site-packages/numpy/core/fromnumeric.pyc in argmin(a,
axis)
    629         argmin = a.argmin
    630     except AttributeError:
--> 631         return _wrapit(a, 'argmin', axis)
    632     return argmin(axis)
    633

/usr/lib/python2.5/site-packages/numpy/core/fromnumeric.pyc in _wrapit(obj,
method, *args, **kwds)
     35     except AttributeError:
     36         wrap = None
---> 37     result = getattr(asarray(obj),method)(*args, **kwds)
     38     if wrap:
     39         if not isinstance(result, mu.ndarray):

ValueError: attempt to get argmax/argmin of an empty sequence

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090601/8b712428/attachment.html 


More information about the Numpy-discussion mailing list