Utility
- ivy.all(x, /, *, axis=None, keepdims=False, out=None)[source]
Tests 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 beTrue
.- Parameters
x (
Union
[Array
,NativeArray
]) – input array.axis (
Optional
[Union
[int
,Sequence
[int
]]]) – axis or axes along which to perform a logical AND reduction. By default, a (default:None
) 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 validaxis
must be an integer on the interval[-N, N)
, whereN
is the rank (number of dimensions) ofx
. If anaxis
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 invalidaxis
, the function must raise an exception. DefaultNone
.keepdims (
bool
) – IfTrue
, the reduced axes (dimensions) must be included in the result as (default:False
) singleton dimensions, and, accordingly, the result must be compatible with the input array (see broadcasting). Otherwise, ifFalse
, the reduced axes (dimensions) must not be included in the result. Default:False
.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
- 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.Functional 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.NativeArray
input:>>> x = ivy.native_array([1, 2, 3]) >>> y = ivy.all(x) >>> 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.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]
Tests 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 beFalse
.- Parameters
x (
Union
[Array
,NativeArray
]) – input array.axis (
Optional
[Union
[int
,Sequence
[int
]]]) – axis or axes along which to perform a logical OR reduction. By default, a (default:None
) 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 validaxis
must be an integer on the interval[-N, N)
, whereN
is the rank (number of dimensions) ofx
. If anaxis
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 invalidaxis
, the function must raise an exception. Default:None
.keepdims (
bool
) – IfTrue
, the reduced axes (dimensions) must be included in the result as (default:False
) singleton dimensions, and, accordingly, the result must be compatible with the input array (see broadcasting). Otherwise, ifFalse
, the reduced axes (dimensions) must not be included in the result. Default:False
.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
- 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.Functional 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.NativeArray
input:>>> x = ivy.native_array([2, 3, 4]) >>> y = ivy.any(x) >>> 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) }
>>> x = ivy.Container(a=ivy.array([0, 1, 2]), b=ivy.array([3, 4, 5])) >>> y = x.any() >>> print(y) { a: ivy.array(True), b: ivy.array(True) }
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 or in the utility forum!