[Numpy-discussion] NetCDF4/numpy question

Olivier Delalleau shish@keba...
Fri Jan 27 15:42:59 CST 2012


What are the types and shapes of modelData and dataMin? (it works for me
with modelData a (3, 4) numpy array and dataMin a Python float, with numpy
1.6.1)

-=- Olivier

2012/1/27 Howard <howard@renci.org>

>  Hi all
>
> I am a fairly recent convert to python and I have got a question that's
> got me stumped.  I hope this is the right mailing list: here goes :)
>
> I am reading some time series data out of a netcdf file a single timestep
> at a time.  If the data is NaN, I want to reset it to the minimum of the
> dataset over all timesteps (which I already know).  The data is in a
> variable of type numpy.ma.core.MaskedArray called modelData.
>
> If I do this:
>
>       for i in range(len(modelData)):
>          if math.isnan(modelData[i]):
>             modelData[i] = dataMin
>
> I get the effect I want, If I do this:
>
>    modelData[np.isnan(modelData)] = dataMin
>
> it doesn't seem to be working.  Of course I could just do the first one,
> but len(modelData) is about 3.5 million, and it's taking about 20 seconds
> to run.  This is happening inside of a rendering loop, so I'd like it to be
> as fast as possible, and I thought the second one might be faster, and
> maybe it is, but it doesn't seem to be working! :)
>
> Any ideas would be much appreciated.
>
> Thanks
> Howard
>
> --
> Howard Lander <howard@renci.org>
> Senior Research Software Developer
> Renaissance Computing Institute (RENCI) <http://www.renci.org>
> The University of North Carolina at Chapel Hill
> Duke University
> North Carolina State University
> 100 Europa Drive
> Suite 540
> Chapel Hill, NC 27517
> 919-445-9651
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20120127/0cde807b/attachment.html 


More information about the NumPy-Discussion mailing list