not_equal#

ivy.not_equal(x1, x2, /, *, out=None)[source]#

Compute the truth value of x1_i != x2_i for each element x1_i of the input array x1 with the respective element x2_i of the input array x2.

Special Cases

For real-valued floating-point operands,

  • If x1_i is NaN or x2_i is NaN, the result is True.

  • If x1_i is +infinity and x2_i is -infinity, the result is True.

  • If x1_i is -infinity and x2_i is +infinity, the result is True.

  • If x1_i is a finite number, x2_i is a finite number, and x1_i does not equal x2_i, the result is True.

  • In the remaining cases, the result is False.

For complex floating-point operands, let a = real(x1_i), b = imag(x1_i), c = real(x2_i), d = imag(x2_i), and

  • If a, b, c, or d is NaN, the result is True.

  • In the remaining cases, the result is the logical OR of the equality comparison between the real values a and c (real components) and between the real values b and d (imaginary components), as described above for real-valued floating-point operands (i.e., a != c OR b != d).

Parameters:
  • x1 (Union[float, Array, NativeArray, Container]) – first input array. Should have a numeric data type.

  • x2 (Union[float, Array, NativeArray, Container]) – second input array. Must be compatible with x1 (see ref:broadcasting). Should have a numeric data type.

  • 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 – an array containing the element-wise results. The returned array must have a data type of bool.

This function 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 simplicity, but this function is nestable, and therefore also accepts ivy.Container instances in place of any of the arguments.

Examples

With ivy.Array inputs:

>>> x1 = ivy.array([1, 0, 1, 1])
>>> x2 = ivy.array([1, 0, 0, -1])
>>> y = ivy.not_equal(x1, x2)
>>> print(y)
ivy.array([False, False, True, True])
>>> x1 = ivy.array([1, 0, 1, 0])
>>> x2 = ivy.array([0, 1, 0, 1])
>>> y = ivy.not_equal(x1, x2)
>>> print(y)
ivy.array([True, True, True, True])
>>> x1 = ivy.array([1, -1, 1, -1])
>>> x2 = ivy.array([0, -1, 1, 0])
>>> y = ivy.zeros(4)
>>> ivy.not_equal(x1, x2, out=y)
>>> print(y)
ivy.array([1., 0., 0., 1.])
>>> x1 = ivy.array([1, -1, 1, -1])
>>> x2 = ivy.array([0, -1, 1, 0])
>>> y = ivy.not_equal(x1, x2, out=x1)
>>> print(y)
ivy.array([1, 0, 0, 1])

With a mix of ivy.Array and ivy.NativeArray inputs:

>>> x1 = ivy.native_array([1, 2])
>>> x2 = ivy.array([1, 2])
>>> y = ivy.not_equal(x1, x2)
>>> print(y)
ivy.array([False, False])
>>> x1 = ivy.native_array([1, -1])
>>> x2 = ivy.array([0, 1])
>>> y = ivy.not_equal(x1, x2)
>>> print(y)
ivy.array([True, True])
>>> x1 = ivy.native_array([1, -1, 1, -1])
>>> x2 = ivy.native_array([0, -1, 1, 0])
>>> y = ivy.zeros(4)
>>> ivy.not_equal(x1, x2, out=y)
>>> print(y)
ivy.array([1., 0., 0., 1.])
>>> x1 = ivy.native_array([1, 2, 3, 4])
>>> x2 = ivy.native_array([0, 2, 3, 4])
>>> y = ivy.zeros(4)
>>> ivy.not_equal(x1, x2, out=y)
>>> print(y)
ivy.array([1., 0., 0., 0.])

With ivy.Container input:

>>> x1 = ivy.Container(a=ivy.array([1, 0, 3]),
...                    b=ivy.array([1, 2, 3]),
...                    c=ivy.native_array([1, 2, 4]))
>>> x2 = ivy.Container(a=ivy.array([1, 2, 3]),
...                    b=ivy.array([1, 2, 3]),
...                    c=ivy.native_array([1, 2, 4]))
>>> y = ivy.not_equal(x1, x2)
>>> print(y)
{
    a: ivy.array([False, True, False]),
    b: ivy.array([False, False, False]),
    c: ivy.array([False, False, False])
}
>>> x1 = ivy.Container(a=ivy.native_array([0, 1, 0]),
...                    b=ivy.array([1, 2, 3]),
...                    c=ivy.native_array([1.0, 2.0, 4.0]))
>>> x2 = ivy.Container(a=ivy.array([1, 2, 3]),
...                    b=ivy.native_array([1.1, 2.1, 3.1]),
...                    c=ivy.native_array([1, 2, 4]))
>>> y = ivy.not_equal(x1, x2)
>>> print(y)
{
    a: ivy.array([True, True, True]),
    b: ivy.array([True, True, True]),
    c: ivy.array([False, False, False])
}

With a mix of ivy.Array and ivy.Container inputs:

>>> x1 = ivy.Container(a=ivy.array([1, 2, 3]),
...                    b=ivy.array([1, 3, 5]))
>>> x2 = ivy.Container(a=ivy.array([1, 2, 3]),
...                    b=ivy.array([1, 4, 5]))
>>> y = ivy.not_equal(x1, x2)
>>> print(y)
{
    a: ivy.array([False, False, False]),
    b: ivy.array([False, True, False])
}
>>> x1 = ivy.Container(a=ivy.array([1.0, 2.0, 3.0]),
...                    b=ivy.array([1, 4, 5]))
>>> x2 = ivy.Container(a=ivy.array([1, 2, 3.0]),
...                    b=ivy.array([1.0, 4.0, 5.0]))
>>> y = ivy.not_equal(x1, x2)
>>> print(y)
{
    a: ivy.array([False, False, False]),
    b: ivy.array([False, False, False])
}
Array.not_equal(self, x2, /, *, out=None)[source]#

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

Parameters:
  • self (Array) – first input array. May have any data type.

  • x2 (Union[float, Array, NativeArray]) – second input array. Must be compatible with self (see broadcasting).

  • 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 – an array containing the element-wise results. The returned array must have a data type of bool.

Examples

With ivy.Array inputs:

>>> x1 = ivy.array([2., 7., 9.])
>>> x2 = ivy.array([1., 7., 9.])
>>> y = x1.not_equal(x2)
>>> print(y)
ivy.array([True, False, False])

With mixed ivy.Array and ivy.NativeArray inputs:

>>> x1 = ivy.array([2.5, 7.3, 9.375])
>>> x2 = ivy.native_array([2.5, 2.9, 9.375])
>>> y = x1.not_equal(x2)
>>> print(y)
ivy.array([False, True,  False])

With mixed ivy.Array and float inputs:

>>> x1 = ivy.array([2.5, 7.3, 9.375])
>>> x2 = 7.3
>>> y = x1.not_equal(x2)
>>> print(y)
ivy.array([True, False, True])

With mixed ivy.Container and ivy.Array inputs:

>>> x1 = ivy.array([3., 1., 0.9])
>>> x2 = ivy.Container(a=ivy.array([12., 3.5, 6.3]), b=ivy.array([3., 1., 0.9]))
>>> y = x1.not_equal(x2)
>>> print(y)
{
    a: ivy.array([True, True, True]),
    b: ivy.array([False, False, False])
}
Container.not_equal(self, x2, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • self (Container) – input array or container. May have any data type.

  • x2 (Union[Container, Array, NativeArray]) – input array or container. Must be compatible with self (see broadcasting). May have any data type.

  • 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.

  • 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 – a container containing the element-wise results. The returned container must have a data type of bool.

Examples

With ivy.Container inputs:

>>> x1 = ivy.Container(a=ivy.array([12, 3.5, 6.3]), b=ivy.array([3., 1., 0.9]))
>>> x2 = ivy.Container(a=ivy.array([12, 2.3, 3]), b=ivy.array([2.4, 3., 2.]))
>>> y = x1.not_equal(x2)
>>> print(y)
{
    a: ivy.array([False, True, True]),
    b: ivy.array([True, True, True])
}

With mixed ivy.Container and ivy.Array inputs:

>>> x1 = ivy.Container(a=ivy.array([12., 3.5, 6.3]), b=ivy.array([3., 1., 0.9]))
>>> x2 = ivy.array([3., 1., 0.9])
>>> y = x1.not_equal(x2)
>>> print(y)
{
    a: ivy.array([True, True, True]),
    b: ivy.array([False, False, False])
}