Utility#

ivy.all(x, /, *, axis=None, keepdims=False, out=None)[source]#

Test whether all input array elements evaluate to True along a specified axis.

Note

Positive infinity, negative infinity, and NaN must evaluate to True.

Note

If x is an empty array or the size of the axis (dimension) along which to evaluate elements is zero, the test result must be True.

Parameters:
  • x (Union[Array, NativeArray]) – input array.

  • axis (Optional[Union[int, Sequence[int]]], default: None) – axis or axes along which to perform a logical AND reduction. By default, a logical AND reduction must be performed over the entire array. If a tuple of integers, logical AND reductions must be performed over multiple axes. A valid axis must be an integer on the interval [-N, N), where N is the rank (number of dimensions) of x. If an axis is specified as a negative integer, the function must determine the axis along which to perform a reduction by counting backward from the last dimension (where -1 refers to the last dimension). If provided an invalid axis, the function must raise an exception. Default None.

  • keepdims (bool, default: False) – If True, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see broadcasting). Otherwise, if False, the reduced axes (dimensions) must not be included in the result. Default: False.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – if a logical AND reduction was performed over the entire array, the returned array must be a zero-dimensional array containing the test result; otherwise, the returned array must be a non-zero-dimensional array containing the test results. The returned array must have a data type of bool.

This method conforms to the Array API Standard. This docstring is an extension of the docstring in the standard.

Both the description and the type hints above assumes an array input for simplicit y,but this function is nestable, and therefore also accepts ivy.Container instances in place of any of the arguments.

Examples

With ivy.Array input:

>>> x = ivy.array([1, 2, 3])
>>> y = ivy.all(x)
>>> print(y)
ivy.array(True)
>>> x = ivy.array([[0],[1]])
>>> y = ivy.zeros((1,1), dtype='bool')
>>> a = ivy.all(x, axis=0, out = y, keepdims=True)
>>> print(a)
ivy.array([[False]])
>>> x = ivy.array(False)
>>> y = ivy.all(ivy.array([[0, 4],[1, 5]]), axis=(0,1), out=x, keepdims=False)
>>> print(y)
ivy.array(False)
>>> x = ivy.array(False)
>>> y = ivy.all(ivy.array([[[0], [1]], [[1], [1]]]), axis=(0,1,2), out=x,
...             keepdims=False)
>>> print(y)
ivy.array(False)

With ivy.Container input:

>>> x = ivy.Container(a=ivy.array([0, 1, 2]), b=ivy.array([3, 4, 5]))
>>> y = ivy.all(x)
>>> print(y)
{
    a: ivy.array(False),
    b: ivy.array(True)
}
>>> x = ivy.Container(a=ivy.native_array([0, 1, 2]),b=ivy.array([3, 4, 5]))
>>> y = ivy.all(x)
>>> print(y)
{
    a: ivy.array(False),
    b: ivy.array(True)
}
ivy.any(x, /, *, axis=None, keepdims=False, out=None)[source]#

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

Note

Positive infinity, negative infinity, and NaN must evaluate to True.

Note

If x is an empty array or the size of the axis (dimension) along which to evaluate elements is zero, the test result must be False.

Parameters:
  • x (Union[Array, NativeArray]) – input array.

  • axis (Optional[Union[int, Sequence[int]]], default: None) – axis or axes along which to perform a logical OR reduction. By default, a logical OR reduction must be performed over the entire array. If a tuple of integers, logical OR reductions must be performed over multiple axes. A valid axis must be an integer on the interval [-N, N), where N is the rank (number of dimensions) of x. If an axis is specified as a negative integer, the function must determine the axis along which to perform a reduction by counting backward from the last dimension (where -1 refers to the last dimension). If provided an invalid axis, the function must raise an exception. Default: None.

  • keepdims (bool, default: False) – If True, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see broadcasting). Otherwise, if False, the reduced axes (dimensions) must not be included in the result. Default: False.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – if a logical OR reduction was performed over the entire array, the returned array must be a zero-dimensional array containing the test result; otherwise, the returned array must be a non-zero-dimensional array containing the test results. The returned array must have a data type of bool.

This method conforms to the Array API Standard. This docstring is an extension of the docstring in the standard.

Both the description and the type hints above assumes an array input for simplicit y,but this function is nestable, and therefore also accepts ivy.Container instances in place of any of the arguments.

Examples

With ivy.Array input:

>>> x = ivy.array([2, 3, 4])
>>> y = ivy.any(x)
>>> print(y)
ivy.array(True)
>>> x = ivy.array([[0],[1]])
>>> y = ivy.zeros((1,1), dtype='bool')
>>> a = ivy.any(x, axis=0, out = y, keepdims=True)
>>> print(a)
ivy.array([[True]])
>>> x=ivy.array(False)
>>> y=ivy.any(ivy.array([[0, 3],[1, 4]]), axis=(0,1), out=x, keepdims=False)
>>> print(y)
ivy.array(True)
>>> x=ivy.array(False)
>>> y=ivy.any(ivy.array([[[0],[1]],[[1],[1]]]),axis=(0,1,2), out=x, keepdims=False)
>>> print(y)
ivy.array(True)

With ivy.Container input:

>>> x = ivy.Container(a=ivy.array([0, 1, 2]), b=ivy.array([3, 4, 5]))
>>> y = ivy.any(x)
>>> print(y)
{
    a: ivy.array(True),
    b: ivy.array(True)
}
ivy.load(filepath, format=None, type='module')[source]#
ivy.save(item, filepath, format=None)[source]#

This should have hopefully given you an overview of the utility submodule, if you have any questions, please feel free to reach out on our discord in the utility channel!