[SciPy-user] masking large arrays

Pierre GM pgmdevlist at gmail.com
Thu May 24 09:08:38 EDT 2007


Emanuele,

> Actually what i was trying was to  get a matrix with zeros where zeros
> appear in the mask (y in your example) and the value of the original array
> where the mask is set to 1.

It seems you think backwards: with a masked array, the values where the mask 
is True (1) are discarded, and only the values where the mask is False(0) are 
used. You could first try to invert your mask (by logical_not, for example), 
and then fill the masked_array with zero.

newimg = masked_array(img, mask=logical_not(initialmask)).filled(0)



More information about the SciPy-User mailing list