isnan surprise

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

isnan surprise

Keith Goodman
>> x = np.array([1.0])
>> np.isnan(x)
   array([False], dtype=bool)  # <----- Expected
>> np.isnan(x,x)
   array([ 0.])  # <----- Surprise (to me)

The same happens with isfinite, isinf, etc.

My use case (self.x is an array):

    def isnan(self):
        y = self.copy()
        np.isnan(y.x, y.x)
        return y

Then when I try to do

myobj[myobj.isnan()] = 0

I get (since myobj.isnan() are floats)

IndexError: arrays used as indices must be of integer (or boolean) type
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: isnan surprise

Keith Goodman
On Sun, May 25, 2008 at 11:13 AM, Keith Goodman <[hidden email]> wrote:
>>> x = np.array([1.0])
>>> np.isnan(x)
>   array([False], dtype=bool)  # <----- Expected
>>> np.isnan(x,x)
>   array([ 0.])  # <----- Surprise (to me)

I guess this is not surprising since I'm asking isnan to put the
answer in a float array.
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: isnan surprise

Robert Kern-2
On Sun, May 25, 2008 at 1:17 PM, Keith Goodman <[hidden email]> wrote:
> On Sun, May 25, 2008 at 11:13 AM, Keith Goodman <[hidden email]> wrote:
>>>> x = np.array([1.0])
>>>> np.isnan(x)
>>   array([False], dtype=bool)  # <----- Expected
>>>> np.isnan(x,x)
>>   array([ 0.])  # <----- Surprise (to me)
>
> I guess this is not surprising since I'm asking isnan to put the
> answer in a float array.

Correct.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
 -- Umberto Eco
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion