Set data array elements depending on a condition.
Elements are set differently depending on where the condition is True or False. Two assignment values are given. From one of them, the data array is set where the condition is True and where the condition is False, the data array is set from the other.
Each assignment value may either contain a single datum, or is an array-like object which is broadcastable shape of the data array.
Missing data
The treatment of missing data elements depends on the value of the hardmask attribute. If it is True then masked elements will not unmasked, otherwise masked elements may be set to any value.
In either case, unmasked elements may be set to any value (including missing data).
Unmasked elements may be set to missing data by assignment to the cf.masked constant or by assignment to a value which contains masked elements.
Parameters : | x, y :
condition : optional
|
---|---|
Returns : | None |
See also
Examples
Set data array values to 15 everywhere:
>>> d.setdata(15, None)
Set all negative data array values to zero and leave all other elements unchanged:
>>> d.setdata(0, None, d<0)
Multiply all positive elements by -1 and set other elements to 3.14:
>>> d.setdata(-d, 3.14, d>0)
Set all values less than 280 and greater than 290 to missing data:
>>> d.setdata(cf.masked, None, (d < 280) | (d > 290))