[Numpy-discussion] nan_to_num and bool arrays

Keith Goodman kwgoodman@gmail....
Fri Dec 11 10:21:22 CST 2009


On Fri, Dec 11, 2009 at 12:50 AM, Nicolas Rougier
<Nicolas.Rougier@loria.fr> wrote:
>
> Hello,
>
> Using both numpy 1.3.0 and 1.4.0rc1 I got the following exception using
> nan_to_num on a bool array, is that the expected behavior ?
>
>
>>>> import numpy
>>>> Z = numpy.zeros((3,3),dtype=bool)
>>>> numpy.nan_to_num(Z)
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>  File "/usr/lib/python2.6/dist-packages/numpy/lib/type_check.py", line
> 374, in nan_to_num
>    maxf, minf = _getmaxmin(y.dtype.type)
>  File "/usr/lib/python2.6/dist-packages/numpy/lib/type_check.py", line
> 307, in _getmaxmin
>    f = getlimits.finfo(t)
>  File "/usr/lib/python2.6/dist-packages/numpy/core/getlimits.py", line
> 103, in __new__
>    raise ValueError, "data type %r not inexact" % (dtype)
> ValueError: data type <type 'numpy.bool_'> not inexact

I guess a check for bool could be added at the top of nan_to_num. If
the input x is a bool then nan_to_num would just return x unchanged.
Or perhaps

maxf, minf = _getmaxmin(y.dtype.type)

could return False, True.

Best bet is probably to file a ticket. And then pray.


More information about the NumPy-Discussion mailing list