[Numpy-discussion] compressed and sqrt in numpy.ma

Pierre GM pgmdevlist@gmail....
Tue Sep 9 13:18:17 CDT 2008

On Tuesday 09 September 2008 14:14:48 Charles Doutriaux wrote:
> The following is causing our code to crash, shouldn't .data be just ones ?
>  >>> a = numpy.ma.ones((2,2))
>  >>> b = numpy.ma.sqrt(a)
>  >>> b.compressed().data

When you use compressed(), you get a ndarray (or a subclass, depending on the 
_baseclass attribute), but no longer a MaskedArray. Therefore, the '.data' 
attribute is the corresponding ndarray.data.
In your example, just use b.compressed()

More information about the Numpy-discussion mailing list