[Numpy-discussion] Standard functions (z-score) on nan (again)

Anne Archibald peridot.faceted at gmail.com
Thu Sep 25 17:59:13 EDT 2008


2008/9/25 Peter Saffrey <pzs at dcs.gla.ac.uk>:
> I've bodged my way through my median problems (see previous postings). Now I
> need to take a z-score of an array that might contain nans. At the moment, if
> the array, which is 7000 elements, contains 1 nan or more, all the results come
> out as nan.
>
> My other problem is that my array is indexed from somewhere else - position 0
> holds the value for a particular id, position 1 holds the value for a particular
> id and so on, so if I remove the nans, all the indices are messed up. Can
> anybody suggest a sensible fix for this problem?
>
> I know I should really be using masked arrays, but I can't seem to find a
> masked-array version of zs. Is there one?

Just keep an array of indices:

c = ~np.isnan(A)

Aclean = A[c]
indices = np.arange(len(A))[c]

Then the original index of Aclean[i] is indices[i].

Anne



More information about the NumPy-Discussion mailing list