cf.Data.where

Data.where(condition, x=None, y=None, i=False, _debug=False)[source]

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:
condition : optional

Define the condition which determines how to set the data array. The condition is any object which is broadcastable to the data array shape. The condition is True where the object broadcast to the data array shape is True. If condition is unset then it defaults to a condition of True everywhere.

x, y :

Specify the assignment value. Where the condition defined by the arg and kwargs arguments is True, set the data array from x and where the condition is False, set the data array from y. Arguments x and y are each one of:

  • None. The appropriate elements of the data array are unchanged.
  • Any object which is broadcastable to the data array’s shape. The appropriate elements of the data array are set to the corresponding values from the object broadcast to the data array shape.
i : bool, optional

If True then update the data array in place. By default a new data array is created.

Returns:

out: cf.Data

Examples: