equal#
- ivy.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.
- Parameters:
x1 (
Union
[float
,Array
,NativeArray
,Container
]) – first input array. May have any data type.x2 (
Union
[float
,Array
,NativeArray
,Container
]) – second input array. Must be compatible with x1 (with Broadcasting). May have any 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:
- Returns:
ret – an array containing the element-wise results. The returned array must have a data type of bool.
Special cases
For real-valued floating-point operands,
If
x1_i
isNaN
orx2_i
isNaN
, the result isFalse
.If
x1_i
is+infinity
andx2_i
is+infinity
, the result isTrue
.If
x1_i
is-infinity
andx2_i
is-infinity
, the result isTrue
.If
x1_i
is-0
andx2_i
is either+0
or-0
, the result isTrue
.If
x1_i
is+0
andx2_i
is either+0
or-0
, the result isTrue
.If
x1_i
is a finite number,x2_i
is a finite number, andx1_i
equalsx2_i
, the result isTrue
.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)
, andIf
a
,b
,c
, ord
isNaN
, the result isFalse
.In the remaining cases, the result is the logical AND of the equality comparison between the real values
a
andc
(real components) and between the real valuesb
andd
(imaginary components), as described above for real-valued floating-point operands (i.e.,a == c AND b == d
).
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 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([2., 7., 9.]) >>> x2 = ivy.array([1., 7., 9.]) >>> y = ivy.equal(x1, x2) >>> print(y) ivy.array([False, True, True])
With mixed
ivy.Array
andivy.NativeArray
inputs:>>> x1 = ivy.array([5, 6, 9]) >>> x2 = ivy.native_array([2, 6, 2]) >>> y = ivy.equal(x1, x2) >>> print(y) ivy.array([False, True, False])
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 = ivy.equal(x1, x2) >>> print(y) { a: ivy.array([True, False, False]), b: ivy.array([False, False, False]) }
With mixed
ivy.Container
andivy.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 = ivy.equal(x1, x2) >>> print(y) { a: ivy.array([False, False, False]), b: ivy.array([True, True, True]) }
- Array.equal(self, x2, /, *, out=None)[source]#
ivy.Array instance method variant of ivy.equal. This method simply wraps the function, and so the docstring for ivy.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 withself
(see broadcasting). May have any 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
.
Examples
With
ivy.Array
inputs:>>> x1 = ivy.array([2., 7., 9.]) >>> x2 = ivy.array([1., 7., 9.]) >>> y = x1.equal(x2) >>> print(y) ivy.array([False, True, True])
With mixed
ivy.Array
andivy.NativeArray
inputs:>>> x1 = ivy.array([2.5, 7.3, 9.375]) >>> x2 = ivy.native_array([2.5, 2.9, 9.375]) >>> y = x1.equal(x2) >>> print(y) ivy.array([True, False, True])
With mixed
ivy.Array
and float inputs:>>> x1 = ivy.array([2.5, 7.3, 9.375]) >>> x2 = 7.3 >>> y = x1.equal(x2) >>> print(y) ivy.array([False, True, False])
With mixed
ivy.Container
andivy.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.equal(x2) >>> print(y) { a: ivy.array([False, False, False]), b: ivy.array([True, True, True]) }
- Container.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.equal. This method simply wraps the function, and so the docstring for ivy.equal also applies to this method with minimal changes.
- Parameters:
x1 – input array or container. May have any data type.
x2 (
Union
[Container
,Array
,NativeArray
]) – input array or container. Must be compatible withx1
(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 isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.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
.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.equal(x2)
>>> print(y)
{ – a: ivy.array([True, False, False]), b: ivy.array([False, False, False])
}
With mixed
ivy.Container
andivy.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.equal(x2)
>>> print(y)
{ – a: ivy.array([False, False, False]), b: ivy.array([True, True, True])
}