[Numpy-discussion] Why NaN?

josef.pktd@gmai... josef.pktd@gmai...
Tue Aug 4 12:05:01 CDT 2009

```On Tue, Aug 4, 2009 at 12:59 PM, Keith Goodman<kwgoodman@gmail.com> wrote:
> On Tue, Aug 4, 2009 at 9:54 AM, Keith Goodman<kwgoodman@gmail.com> wrote:
>> On Tue, Aug 4, 2009 at 9:46 AM, Gökhan Sever<gokhansever@gmail.com> wrote:
>>> Hello,
>>>
>>> I know this has to have a very simple answer, but stuck at this very moment
>>> and can't get a meaningful result out of np.mean()
>>>
>>>
>>> In [121]: a = array([NaN, 4, NaN, 12])
>>>
>>> In [122]: b = array([NaN, 2, NaN, 3])
>>>
>>> In [123]: c = a/b
>>>
>>> In [124]: mean(c)
>>> Out[124]: nan
>>>
>>> In [125]: mean a
>>> --------> mean(a)
>>> Out[125]: nan
>>>
>>> Further when I tried:
>>>
>>> In [138]: c
>>> Out[138]: array([ NaN,   2.,  NaN,   4.])
>>>
>>> In [139]: np.where(c==NaN)
>>> Out[139]: (array([], dtype=int32),)
>>>
>>>
>>> In [141]: mask = [c != NaN]
>>>
>>> Out[142]: [array([ True,  True,  True,  True], dtype=bool)]
>>>
>>>
>>> Any ideas?
>>
>>>> a = array([NaN, 4, NaN, 12])
>>>> b = array([NaN, 2, NaN, 3])
>>>> c = a/b
>>>> from scipy import stats
>>>> stats.nan [tab]
>> stats.nanmean    stats.nanmedian  stats.nanstd
>>>> stats.nanmean(c)
>>   3.0
>>>> stats.nanmean(a)
>>   8.0
>>>> c[isnan(c)]
>>   array([ NaN,  NaN])
>
> One more:
>
>>> c[isfinite(c)].mean()
>   3.0
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>

What's going on with the response time here?

I cannot even finish reading the question and start python.

Josef
```