[Numpy-discussion] numpy masked array oddity
Mon May 5 14:10:56 CDT 2008
Pierre GM wrote:
> On Monday 05 May 2008 13:19:40 Russell E. Owen wrote:
>> The object returned by maskedArray.compressed() appears to be a normal
>> numpy array (based on repr output), but in reality it has some
>> surprising differences:
> * I assume you're not using the latest version of numpy, are you ? If you
> were, the .sort() method would work.
He is clearly using the older version; it is accessed via numpy.core.ma.
> * Currently, the output of MaskedArray.compressed() is indeed a MaskedArray,
> where the missing values are skipped. If you need a regular ndarray, just a
> view as Robert suggested. Christopher's suggestion is equivalent.
> * An alternative would be to force the output of MaskedArray.compressed() to
> type(MaskedArray._baseclass), where the _baseclass attribute is the class of
> the underlying array: usually it's only ndarray, but it can be any subclass.
> Changing this behavior would not break anything in TimeSeries.
This alternative makes sense to me--I expect most use cases would be
most efficient with compressed yielding a plain ndarray. I don't see
any gain in keeping it as a masked array, and having to manually convert
it. (I don't see how the _baseclass conversion would work with the
baseclass as a matrix, though.)
> * I need to fix a bug in compressed when the underlying array is a matrix: I
> can take care of the alternative at the same time. What are the opinions on
> that matter ?
> Numpy-discussion mailing list
More information about the Numpy-discussion