[Numpy-discussion] numpy.ma.compress

Pierre GM pgmdevlist@gmail....
Wed Jan 23 17:10:43 CST 2008


On Wednesday 23 January 2008 17:05:25 Stefan van der Walt wrote:
> On Wed, Jan 23, 2008 at 11:17:51AM -1000, Eric Firing wrote:
> > Pierre,
> >
> > numpy.compress exists, but numpy.ma.compress does not; is this
> > intentional?
>
> Looks like x.compress exists, but it doesn't work as expected:
>
> x = N.ma.array([1,2,3],mask=[True,False,Fals])
> x.compress(x<2)
>
> throws
>
> ValueError: total size of new array must be unchanged

Hardly a surprise: .compress is inherited from ndarray, and doesn't know how 
to handle the mask. We end up with a mask that doesn't have the size of the 
data, hence the ValueError. 

Stefan's modification should work for now. I'm working on a version closer to 
the numpy original (that accepts the other arguments as well), I'll try to 
commit it later tonight.

Thanks again for your help !


More information about the Numpy-discussion mailing list