cf.Data.any

Data.any(axis=None, keepdims=True, split_every=None)[source]

Test whether any data array elements evaluate to True.

See also

all, allclose, isclose

Parameters
axis: (sequence of) int, optional

Axis or axes along which a logical OR reduction is performed. The default (None) is to perform a logical OR over all the dimensions of the input array. axis may be negative, in which case it counts from the last to the first axis.

keepdims: bool, optional

By default, the axes which are collapsed are left in the result as dimensions with size one, so that the result will broadcast correctly against the input array. If set to False then collapsed axes are removed from the data.

split_every: int or dict, optional

Determines the depth of the recursive aggregation. If set to or more than the number of input chunks, the aggregation will be performed in two steps, one partial collapse per input chunk and a single aggregation at the end. If set to less than that, an intermediate aggregation step will be used, so that any of the intermediate or final aggregation steps operates on no more than split_every inputs. The depth of the aggregation graph will be \(log_{split_every}(input chunks along reduced axes)\). Setting to a low value can reduce cache size and network transfers, at the cost of more CPU and a larger dask graph.

By default, dask heuristically decides on a good value. A default can also be set globally with the split_every key in dask.config. See dask.array.reduction for details.

Returns
Data

Whether or any data array elements evaluate to True.

Examples

>>> d = cf.Data([[0, 2], [0, 4]])
>>> d.any()
<CF Data(1, 1): [[True]]>
>>> d.any(keepdims=False)
<CF Data(1, 1): True>
>>> d.any(axis=0)
<CF Data(1, 2): [[False, True]]>
>>> d.any(axis=1)
<CF Data(2, 1): [[True, True]]>
>>> d.any(axis=())
<CF Data(2, 2): [[False, ..., True]]>
>>> d[0] = cf.masked
>>> print(d.array)
[[-- --]
 [0 4]]
>>> d.any(axis=0)
<CF Data(1, 2): [[False, True]]>
>>> d.any(axis=1)
<CF Data(2, 1): [[--, True]]>
>>> d[...] = cf.masked
>>> d.any()
<CF Data(1, 1): [[--]]>
>>> bool(d.any())
False
>>> bool(d.any(keepdims=False))
False