[Numpy-discussion] C-api and masked arrays

Pierre GM pgmdevlist at gmail.com
Mon Mar 1 10:21:13 EST 2010


On Mar 1, 2010, at 10:04 AM, Martin Raspaud wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi all,
> 
> We are using at the moment a c extension which should manipulate masked arrays.
> What we do is to fill the masked array with a given value (say 65535 if we run
> uint16 arrays), do the manipulation, and convert back to masked arrays when we
> go back to python.
> 
> This seems like a naive way to do, is there another cleverer way to do it ?


Keep in mind that masked arrays are pure Python (because I still don't speak C), so there's no real proper C way to deal with them. That depends on the kind of manipulation you have in mind. If the underlying value is not important, you don't have to fill the array, just use its .data (the underlying ndarray). If you expect problems down the road (such as NaNs popping up), then yes, filling the masked array beforehand is the way to go. Don't forget to stitch the mask at the end...


More information about the NumPy-Discussion mailing list