[Numpy-discussion] Generically Creating Intermediate Data Compatible with Either ndarray or MasledArray Types

Eric Firing efiring@hawaii....
Tue Mar 11 14:42:55 CDT 2008


Alex,

I don't know if it works for older versions of numpy, but with svn you 
can simply use the astype() method of the array.  If the array is masked 
it seems to work correctly, although it does not update the fill_value 
to the default for the new type.

Eric

Alexander Michael wrote:
> I have a function that I would like to work with both MaskedArray's
> and ndarray's. The only blocker for this particular function is the
> need to create some stand-in data that is appropriately either a
> MaskedArray or an ndarray. Currently I have:
> 
> dummy = numpy.ones(data.shape, dtype=bool)
> 
> where data has a dtype of float. I've already discovered that
> numpy.ones_like "does the right thing", but how do I do the equivalent
> in conjunction with declaring a new dtype?
> 
> Said another way, how can a create arrays of the same class and
> (possibly) shape as an existing array, but with a different dtype?
> 
> Thanks,
> Alex
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion



More information about the Numpy-discussion mailing list