[Numpy-discussion] C-api and masked arrays

Martin Raspaud martin.raspaud at smhi.se
Mon Mar 1 10:39:58 EST 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Pierre GM skrev:
> 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...

Hi,

We're talking map projections, so that means that the values will move around,
including masked ones...

So filling the array with a given value is a way of projecting the array and the
mask in one shot...

Martin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJLi9/OAAoJEBdvyODiyJI4pIwH/0pCKWOjhgwzC4AWXxXsvwIz
M0kDHIpnZaHzKb1yIhnRJJQtyYsqWCXp9xb1KqGVD1GY6Xf2T8xI61pB17HSrSoY
MvTUXjWHKsu2Uz8eNBfOvyTbfTGs+dtMEjwWGbj+OmZrLERPSGvpldPnsz8vxBsD
QK0oG9aF2lrnHlv9YkHWHp8+XTTPGAVhzcNidic1hlGlhNoE/pcphpB3b8ssVL4H
I+hF9JOzN5di9fjTKDo6rn988gxlxSZx/Im9QQ9A53sAZxxQNn1l5bTB5qACzHPj
qaxY+cyEWJjSe/FI32BdWgPNwLM+7z/L6vPLzyA6rnuyIqgFnJqPGuYT/ZSWsts=
=05+r
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: martin_raspaud.vcf
Type: text/x-vcard
Size: 260 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20100301/50c39270/attachment.vcf>


More information about the NumPy-Discussion mailing list