[Numpy-discussion] numpy masked array oddity

Eric Firing efiring@hawaii....
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:
> 
> Russell:
> 
> * 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.)

Eric

> 
> * 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
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion



More information about the Numpy-discussion mailing list