[SciPy-User] removing multiple occurrences of a specific value (or range of values) from an array

josef.pktd at gmail.com josef.pktd at gmail.com
Mon Jan 10 20:48:12 EST 2011


On Mon, Jan 10, 2011 at 8:42 PM, Brennan Williams
<brennan.williams at visualreservoir.com> wrote:
> I have a numpy array and I use .min(), .max(), .std(), average(..),
> median(...) etc to get various stats values.
>
> Depending on where the data originally came from, the array can contain
> a null value which could be 1.0e+20 or similar (can vary from dataset to
> dataset). Due to rounding errors this can sometimes appear as something
> like 1.0000002004e+20 etc etc.
>
> So I want to be able to correctly calculate the stats values by ignoring
> the null values.
>
> I also want to be able to replace the null values with another value
> (for plotting/exporting).
>
> What's the best way to do this without looping over the elements of the
> array?

If you don't have anything large, then you could just do

x[x>1e19]=np.nan

or filter them out, or convert to masked array.

Josef


>
> Thanks
>
> Brennan
>
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>



More information about the SciPy-User mailing list