[Numpy-discussion] average of array containing NaN

Pierre GM pgmdevlist@gmail....
Mon Jun 25 13:28:50 CDT 2007


On Monday 25 June 2007 14:15:20 Giorgio F. Gilestro wrote:
> Thanks.
> Actually those I care the most are average and std.
> Is there a way to know the number of NaN in an array?

Giorgio,
You could use:
numpy.isnan(x).sum()

But once again 
<push_product>
masked arrays were designed to handle this kind of situation seamlessly. Just 
create a masked_array
masked_array(x, mask=isnan(x))
and use the regular functions/methods on the masked array.
</push_product>


More information about the Numpy-discussion mailing list