[Numpy-discussion] Why NaN?
Tue Aug 4 16:05:18 CDT 2009
On Tue, Aug 4, 2009 at 1:53 PM, Bruce Southey<email@example.com> wrote:
> On Tue, Aug 4, 2009 at 1:40 PM, Gökhan Sever<firstname.lastname@example.org> wrote:
>> This is the loveliest of all solutions:
> This handling of nonfinite elements has come up before.
> Please remember that this only for 1d or flatten array so it not work
> in general especially along an axis.
If you don't want to use nanmean from scipy.stats you could use:
np.nansum(c, axis=0) / (~np.isnan(c)).sum(axis=0)
np.nansum(c, axis=0) / (c == c).sum(axis=0)
But if c contains ints then you'll run into trouble with the division,
so you'll need to protect against that.
More information about the NumPy-Discussion