[SciPy-User] How to ignore NaN values and -32767 in numpy array

Robert Kern robert.kern@gmail....
Mon Aug 22 18:12:33 CDT 2011


On Mon, Aug 22, 2011 at 18:00, questions anon <questions.anon@gmail.com> wrote:
> Thank you, that is good to know, but that is not the case for this. I know I
> have blank data or something in a couple of sections and when I choose to
> print around those figures I still end up with what happens below (shown
> again).
>  [[-- -- -- ..., -- -- --]
>   [-- -- -- ..., -- -- --]
>   [-- -- -- ..., -- -- --]
>   ...,
> And then when I make this into one big array these turn into
>   [ -3.27670000e+04  -3.27670000e+04  -3.27670000e+04 ...,  -3.27670000e+04
>     -3.27670000e+04  -3.27670000e+04]
> Is there a way to identify these blanks and ignore them from the analyses?

Or, right, sorry. The -- indeed are masked values. Somehow, you are
using masked_arrays. I don't know if the netCDF4 module is doing that
for you automatically or if you are using different code than what you
showed.

numpy.concatenate() will ignore that the array is a masked_array and
just treat it as if it were a regular numpy ndarray, and lose the mask
information. You will need to use numpy.ma.concatenate() instead.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco


More information about the SciPy-User mailing list