array_equal#

ivy.array_equal(x0, x1, /)[source]#

Determine whether two input arrays are equal across all elements.

Parameters:
  • x0 (Union[Array, NativeArray]) – The first input array to compare.

  • x1 (Union[Array, NativeArray]) – The second input array to compare.

Return type:

bool

Returns:

ret – Boolean, whether or not the input arrays are equal across all elements.

Examples

>>> x = ivy.array([1,0,1])
>>> y = ivy.array([1,0,-1])
>>> z = ivy.array_equal(x,y)
>>> print(z)
False
>>> a = ivy.array([1, 2])
>>> b = ivy.array([1, 2])
>>> c = ivy.array_equal(a,b)
>>> print(c)
True
>>> i = ivy.array([1, 2])
>>> j = ivy.array([1, 2, 3])
>>> k = ivy.array_equal(i,j)
>>> print(k)
False
Array.array_equal(self, x, /)[source]#

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

Parameters:
  • self (Array) – input array

  • x (Union[Array, NativeArray]) – input array to compare to self

Return type:

bool

Returns:

ret – Boolean, whether or not the input arrays are equal

Examples

>>> x = ivy.array([-1,0])
>>> y = ivy.array([1,0])
>>> z = x.array_equal(y)
>>> print(z)
False
>>> a = ivy.array([1, 2])
>>> b = ivy.array([1, 2])
>>> c = a.array_equal(b)
>>> print(c)
True
>>> i = ivy.array([1, 2])
>>> j = ivy.array([1, 2, 3])
>>> k = i.array_equal(j)
>>> print(k)
False
Container.array_equal(self, x, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#

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

Parameters:
  • self (Union[Array, NativeArray, Container]) – The first input container to compare.

  • x (Union[Array, NativeArray, Container]) – The second input container to compare.

  • 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 – A boolean container indicating whether the two containers are equal at each level.

Examples

>>> a = ivy.array([[0., 1.], [1. ,0.]])
>>> b = ivy.array([[-2., 1.], [1. ,2.]])
>>> c = ivy.array([[0., 1.], [1. ,0.]])
>>> d = ivy.array([[2., 1.], [1. ,2.]])
>>> a1 = ivy.Container(a = a, b = b)
>>> a2 = ivy.Container(a = c, b = d)
>>> y = a1.array_equal(a2)
>>> print(y)
{
    a: True,
    b: False
}
>>> 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.array_equal(x2)
>>> print(y)
{
    a: False,
    b: True
}