all_equal#

ivy.all_equal(*xs, equality_matrix=False)[source]#

Determine whether the inputs are all equal.

Parameters:
  • xs (Iterable[Any]) – inputs to compare.

  • equality_matrix (bool, default: False) – Whether to return a matrix of equalities comparing each input with every other. Default is False.

Return type:

Union[bool, Array, NativeArray]

Returns:

ret – Boolean, whether or not the inputs are equal, or matrix array of booleans if equality_matrix=True is set.

Examples

With ivy.Array inputs:

>>> x1 = ivy.array([1, 1, 0, 0, 1, -1])
>>> x2 = ivy.array([1, 1, 0, 0, 1, -1])
>>> y = ivy.all_equal(x1, x2)
>>> print(y)
True
>>> x1 = ivy.array([0, 0])
>>> x2 = ivy.array([0, 0])
>>> x3 = ivy.array([1, 0])
>>> y = ivy.all_equal(x1, x2, x3, equality_matrix=True)
>>> print(y)
ivy.array([[ True,  True, False],
   [ True,  True, False],
   [False, False,  True]])

With one ivy.Container inputs:

>>> x1 = ivy.Container(a=ivy.array([0, 0, -1, 1, 0]),
...                    b=ivy.array([0, 0, -1, 1, 0]))
>>> x2 = ivy.array([0, 0, -1, 1, 0])
>>> y = ivy.all_equal(x1, x2, equality_matrix=False)
>>> print(y)
{
    a: True,
    b: True
}

With multiple ivy.Container inputs:

>>> x1 = ivy.Container(a=ivy.array([1, 0, 1, 1]),
...                    b=ivy.array([1, 0, 0, 1]))
>>> x2 = ivy.Container(a=ivy.array([1, 0, 1, 1]),
...                    b=ivy.array([1, 0, -1, -1]))
>>> y = ivy.all_equal(x1, x2, equality_matrix=False)
>>> print(y)
{
    a: True,
    b: False
}
Array.all_equal(self, *x2, equality_matrix=False)[source]#

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

Parameters:
  • self (Array) – input array

  • x2 (Iterable[Any]) – input iterable to compare to self

  • equality_matrix (bool, default: False) – Whether to return a matrix of equalities comparing each input with every other. Default is False.

Return type:

Union[bool, Array, NativeArray]

Returns:

ret – Boolean, whether or not the inputs are equal, or matrix array of booleans if equality_matrix=True is set.

Examples

>>> x1 = ivy.array([1, 1, 0, 0, 1, -1])
>>> x2 = ivy.array([1, 1, 0, 0, 1, -1])
>>> y = x1.all_equal(x2)
>>> print(y)
True
>>> x1 = ivy.array([0, 0])
>>> x2 = ivy.array([0, 0])
>>> x3 = ivy.array([1, 0])
>>> y = x1.all_equal(x2, x3, equality_matrix=True)
>>> print(y)
ivy.array([[ True,  True, False],
   [ True,  True, False],
   [False, False,  True]])
Container.all_equal(self, *xs, equality_matrix=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#

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

Parameters:
  • self (Container) – input container.

  • xs (Union[Iterable[Any], Container]) – arrays or containers to be compared to self.

  • equality_matrix (Union[bool, Container], default: False) – Whether to return a matrix of equalities comparing each input with every other. Default is False.

  • key_chains (Optional[Union[List[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.

Return type:

Container

Returns:

ret – Boolean, whether or not the inputs are equal, or matrix container of booleans if equality_matrix=True is set.

Examples

With one ivy.Container instances:

>>> x1 = ivy.Container(a=ivy.array([1, 0, 1, 1]), b=ivy.array([1, -1, 0, 0]))
>>> x2 = ivy.array([1, 0, 1, 1])
>>> y = x1.all_equal(x2, equality_matrix= False)
>>> print(y)
{
    a: True,
    b: False
}
>>> x1 = ivy.Container(a=ivy.array([1, 0, 1, 1]), b=ivy.array([1, -1, 0, 0]))
>>> x2 = ivy.array([1, 0, 1, 1])
>>> y = x1.all_equal(x2, equality_matrix= False)
>>> print(y)
{
    a: True,
    b: False
}

With multiple ivy.Container instances:

>>> x1 = ivy.Container(a=ivy.native_array([1, 0, 0]),
...                    b=ivy.array([1, 2, 3]))
>>> x2 = ivy.Container(a=ivy.native_array([1, 0, 1]),
...                    b=ivy.array([1, 2, 3]))
>>> y = x1.all_equal(x2, equality_matrix= False)
>>> print(y)
{
    a: False,
    b: True
}
>>> x1 = ivy.Container(a=ivy.native_array([1, 0, 0]),
...                    b=ivy.array([1, 2, 3]))
>>> x2 = ivy.Container(a=ivy.native_array([1, 0, 1]),
...                    b=ivy.array([1, 2, 3]))
>>> y = x1.all_equal(x2, equality_matrix= False)
>>> print(y)
{
    a: False,
    b: True
}