[SciPy-user] calculate average by excluding NaN value in Array
Mon Mar 30 10:03:40 CDT 2009
On Mar 30, 2009, at 9:21 AM, Chris Barker wrote:
> David Cournapeau wrote:
>>> nanmean should do what you want,
> Actually, I don't think that's what the OP wanted:
>>>>> b=([3.,2,4, NaN])
>> array([ 2.5, 2.5, 4. , NaN], dtype=float32)
>> I mean that I need is [2.5,2.5,4,5], instead.
> In this case, numpy really is doing the only correct thing, in an
> operation like this, the result should be the same size as the input
> arrays, and the average of NaN and anything else can only be NaN.
Still, masked arrays were defined exactly for that kind of problem.
fix_invalid masks values that are NaNs/Infs.
More information about the SciPy-user