[Numpy-discussion] Recommendations for using numpy ma?
Russell E. Owen
Wed Jul 16 11:28:40 CDT 2008
In article <firstname.lastname@example.org>,
Pierre GM <email@example.com> wrote:
> What used to be numpy.core.ma is now numpy.oldnumeric.ma, but this latter isd
> no longer supported and will disappear soon as well. Just use numpy.ma
> If you really need support to ancient versions of numpy, just check the import
> import numpy.core.ma as ma
> except ImportError:
> import numpy as ma
(I assume you mean the last line to be "import numpy .ma as ma"?)
Thanks! I was afraid I would have to do that, but not having ready
access to ancient versions of numpy I was hoping I was wrong and that
numpy.ma would work for those as well.
However, I plan to assume a modern numpy first, as in:
import numpy.ma as ma
import numpy.core.ma as ma
> Then, you need to replace every mention of numpy.core.ma in your code by ma.
> Your example would then become:
> unmaskedArr = numpy.array(
> mask = mask & self.stretchExcludeBits,
> dtype = float,
> On another note: wha't the problem with 'compressed' ? It should return a
> ndarray, why/how doesn't it work ?
The problem is that the returned array does not support the "sort"
method. Here's an example using numpy 1.0.4:
z = numpy.zeros(10, dtype=float)
m = numpy.zeros(10, dtype=bool)
m = 1
mzc = numpy.ma.array(z, mask=m).compressed()
the last statement fails witH:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
kages/numpy/core/ma.py", line 2132, in not_implemented
raise NotImplementedError, "not yet implemented for numpy.ma arrays"
NotImplementedError: not yet implemented for numpy.ma arrays
This seems like a bug to me. The returned object is reported by "repr"
to be a normal numpy array; there is no obvious way to tell that it is
anything else. Also I didn't see any reason for "compressed" to return
anything except an ordinary array. Oh well.
I reported this on the mailing list awhile ago when I first stumbled
across it, but nobody seemed interested at the time. It wasn't clear to
me whether it was a bug so I dropped it without reporting it formally
(and I've still not reported it formally).
More information about the Numpy-discussion