[Numpy-discussion] surprising behavior of np.asarray on masked arrays

Stéfan van der Walt stefan at sun.ac.za
Thu Dec 5 23:22:18 EST 2013

Hi Faraz

On Thu, 05 Dec 2013 19:14:01 -0800, Faraz Mirzaei wrote:
> If I pass a masked array through np.asarray, I get original unmasked array.

`asarray` disregards any information attached to the underlying ndarray by the
subclass.  To preserve the subclass, you'd need to use `asanyarray`.

The only functions that are aware of masked arrays live inside of `np.ma`, so
you can also use `np.ma.asarray`.

Which behavior in particular would you like to see, since I presume you can
already get hold of the filled array, should you want to?


More information about the NumPy-Discussion mailing list