mindspore.numpy.sometrue(a, axis=None, keepdims=False)[source]

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

Returns single boolean unless axis is not None

  • a (Union[int, float, bool, list, tuple, Tensor]) – Input tensor or object that can be converted to an array.

  • axis (Union[None, int, tuple(int)]) – Axis or axes along which a logical OR reduction is performed. Default: None. If None, perform a logical OR over all the dimensions of the input array. If negative, it counts from the last to the first axis. If tuple of integers, a reduction is performed on multiple axes, instead of a single axis or all the axes as before.

  • keepdims (bool) – Default: False. If True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. If the default value is passed, then keepdims will not be passed through to the any method of sub-classes of ndarray, however any non-default value will be. If the sub-class method does not implement keepdims any exceptions will be raised.


Returns single boolean unless axis is not None

  • TypeError – If input is not array_like or axis is not int or tuple of integers or keepdims is not integer or initial is not scalar.

  • ValueError – If any axis is out of range or duplicate axes exist.

Supported Platforms:

Ascend GPU CPU


>>> import mindspore.numpy as np
>>> x = np.array([1, -2.3, 2.1]).astype('float32')
>>> output = np.sometrue(x)
>>> print(output)