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

Alexander Michael lxander.m at gmail.com
Tue Mar 11 15:10:47 EDT 2008


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



More information about the NumPy-Discussion mailing list