cf.Variable.setitem

Variable.setitem(value, indices=Ellipsis, condition=None, masked=None, other_mask=None, hardmask=None)[source]

Set selected elements of the data array in place.

The value to which the selected elements of the data array will be set may be any object which is broadcastable across the selected elements.

Note the following:

  • f.setitem(value) is equivalent to f.subspace[...]=value.
  • f.setitem(value, indices) is equivalent to f.subspace[indices]=value.
  • If and only if the value to be assigned is the scalar cf.masked (or numpy.ma.masked) then the selected elements of data array’s mask will be set to True (masked). For example, f.setitem(cf.masked, indices) is equivalent to f.setmask(True, indices). This is consistent with the behaviour of numpy masked arrays.
Parameters :
value : array-like

The value to which the selected elements of the data array will be set. Must be an object which is broadcastable across the selected elements.

indices : optional

Any indices as would be accepted by f.subspace. Only elements of the data array described by the indices, and where other criteria (if any) are met, are set to value. By default, the entire data array is considered. How masked elements of the data array are treated depends on the hardmask parameter. The value must be any object broadcastable across the shape implied by indices. Note that f.setitem(value, indices) is equivalent to f.subspace[indices]=value.

condition : scalar or Comparison, optional

A condition applied to each element of the data array specified by `indices` which determines whether or not that element is set to the logically scalar value. The condition is evaluated by checking if each element equals the condition, and if it does then that element is set to value. How masked elements of the data array are treated depends on the hardmask parameter. Note that if condition is a scalar, x, then this is equivalent to the Comparison object cf.eq(x).

masked : bool, optional

If False then each unmasked element of the data array specified by `ndices is set to the logically scalar value. If True then each unmasked element of the data array specified by indices is unmasked and set to the logically scalar value, regardless of the hardmask is parameter.

other_mask : array-like, optional

Each element of the data array specified by indices and which corresponds to an element which evaluates to False from other_mask is set to the logically scalar value. other_mask may be any object which is broadcastable across the shape implied by indices. How masked elements of the data array are treated depends on the hardmask parameter.

hardmask : bool, optional

If True then any selected elements of the data array which are masked will not be unmasked and assigned to. If False then any selected elements of the data array which are masked will be unmasked and assigned to. By default, the value of the instance’s hardmask attribute is used.

Returns :

None

Examples

Previous topic

cf.Variable.select

Next topic

cf.Variable.setmask

This Page