all#

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)
}
Array.all(self, /, *, axis=None, keepdims=False, out=None)[source]#

ivy.Array instance method variant of ivy.all. This method simply wraps the function, and so the docstring for ivy.all also applies to this method with minimal changes.

Parameters:
  • self (Array) – 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 self. 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.

Examples

>>> x = ivy.array([0, 1, 2])
>>> y = x.all()
>>> print(y)
ivy.array(False)
>>> x = ivy.array([[[0, 1], [0, 0]], [[1, 2], [3, 4]]])
>>> y = x.all(axis=1)
>>> print(y)
ivy.array([[False, False],
       [ True,  True]])
Container.all(self, /, *, axis=None, keepdims=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

ivy.Container instance method variant of ivy.all. This method simply wraps the function, and so the docstring for ivy.all also applies to this method with minimal changes.

Parameters:
  • self (Container) – input container.

  • axis (Optional[Union[int, Sequence[int], Container]], 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 self. 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 (Union[bool, Container], 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.

  • key_chains (Optional[Union[Sequence[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

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

Return type:

Container

Returns:

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

Examples

>>> x = ivy.Container(a=ivy.array([0, 1, 2]), b=ivy.array([0, 1, 1]))
>>> y = x.all()
>>> print(y)
{
    a: ivy.array(False),
    b: ivy.array(False)
}