dpnp.any

dpnp.any(a, /, axis=None, out=None, keepdims=False, *, where=True)[source]

Test whether any array element along a given axis evaluates to True.

For full documentation refer to numpy.any.

Parameters:
  • a ({dpnp.ndarray, usm_ndarray}) -- Input array.

  • axis ({None, int, tuple of ints}, optional) -- Axis or axes along which a logical OR reduction is performed. The default 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. Default: None.

  • out ({None, dpnp.ndarray, usm_ndarray}, optional) -- Alternative output array in which to place the result. It must have the same shape as the expected output but the type (of the returned values) will be cast if necessary. Default: None.

  • keepdims (bool, optional) -- If True, the reduced axes (dimensions) are included in the result as singleton dimensions, so that the returned array remains compatible with the input array according to Array Broadcasting rules. Otherwise, if False, the reduced axes are not included in the returned array. Default: False.

Returns:

out -- An array with a data type of bool containing the results of the logical OR reduction is returned unless out is specified. Otherwise, a reference to out is returned. The result has the same shape as a if axis is not None or a is a 0-d array.

Return type:

dpnp.ndarray

Limitations

Parameters where is only supported with its default value. Otherwise NotImplementedError exception will be raised.

See also

dpnp.ndarray.any

equivalent method

dpnp.all

Test whether all elements along a given axis evaluate to True.

Notes

Not a Number (NaN), positive infinity and negative infinity evaluate to True because these are not equal to zero.

Examples

>>> import dpnp as np
>>> x = np.array([[True, False], [True, True]])
>>> np.any(x)
array(True)
>>> np.any(x, axis=0)
array([ True,  True])
>>> x2 = np.array([-1, 0, 5])
>>> np.any(x2)
array(True)
>>> x3 = np.array([1.0, np.nan])
>>> np.any(x3)
array(True)
>>> o = np.array(False)
>>> z = np.any(x2, out=o)
>>> z, o
(array(True), array(True))
>>> # Check now that `z` is a reference to `o`
>>> z is o
True
>>> id(z), id(o) # identity of `z` and `o`
>>> (140053638309840, 140053638309840) # may vary