Elementwise
- ivy.abs(x, /, *, out=None)[source]
Calculates the absolute value for each element
x_i
of the input arrayx
(i.e., the element-wise result has the same magnitude as the respective element inx
but has positive sign).Note
For signed integer data types, the absolute value of the minimum representable integer is implementation-dependent.
Special Cases
For this particular case,
If
x_i
isNaN
, the result isNaN
.If
x_i
is-0
, the result is+0
.If
x_i
is-infinity
, the result is+infinity
.
- Parameters
- Return type
- Returns
ret – an array containing the absolute value of each element in
x
. The returned array must have the same data type asx
.This function conforms to the `Array API Standard
<https (//data-apis.org/array-api/latest/>`_. This docstring is an extension of the)
`docstring <https (//data-apis.org/array-api/latest/API_specification/generated/signatures.elementwise_functions.add.html>`_ )
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
input:>>> x = ivy.array([-1,0,-6]) >>> y = ivy.abs(x) >>> print(y) ivy.array([1, 0, 6])
>>> x = ivy.array([3.7, -7.7, 0, -2, -0]) >>> y = ivy.abs(x) >>> print(y) ivy.array([ 3.7, 7.7, 0., 2., 0.])
>>> x = ivy.array([[1.1, 2.2, 3.3], [-4.4, -5.5, -6.6]]) >>> ivy.abs(x, out=x) >>> print(x) ivy.array([[ 1.1, 2.2, 3.3], [4.4, 5.5, 6.6]])
With
ivy.NativeArray
input:>>> x = ivy.native_array([0, -0, -2.6, -1, 1, 3.6]) >>> y = ivy.abs(x) >>> print(y) ivy.array([ 0., 0., 2.6, 1., 1., 3.6])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([0., 2.6, -3.5]), b=ivy.array([4.5, -5.3, -0, -2.3])) >>> y = ivy.abs(x) >>> print(y) { a: ivy.array([0., 2.6, 3.5]), b: ivy.array([4.5, 5.3, 0., 2.3]) }
- ivy.acos(x, /, *, out=None)[source]
Calculates an implementation-dependent approximation of the principal value of the inverse cosine, having domain [-1, +1] and codomain [+0, +π], for each element x_i of the input array x. Each element-wise result is expressed in radians.
Special cases
For floating-point operands,
If x_i is NaN, the result is NaN.
If x_i is greater than 1, the result is NaN.
If x_i is less than -1, the result is NaN.
If x_i is 1, the result is +0.
- Parameters
- Return type
- Returns
ret – an array containing the inverse cosine of each element in x. The returned array must have a floating-point data type determined by type-promotion.
Examples
With
ivy.Array
input: >>> x = ivy.array([0., 1., -1.]) >>> y = ivy.acos(x) >>> print(y) ivy.array([1.57, 0. , 3.14])>>> x = ivy.array([1., 0., -1.]) >>> y = ivy.zeros(3) >>> ivy.acos(x, out=y) >>> print(y) ivy.array([0. , 1.57, 3.14])
With
ivy.NativeArray
input:>>> x = ivy.array([1., 0., -1.]) >>> y = ivy.acos(x) >>> print(y) ivy.array([0. , 1.57, 3.14])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([0., -1, 1]), b=ivy.array([1., 0., -1])) >>> y = ivy.acos(x) >>> print(y) { a: ivy.array([1.57, 3.14, 0.]), b: ivy.array([0., 1.57, 3.14]) }
- ivy.acosh(x, /, *, out=None)[source]
Calculates an implementation-dependent approximation to the inverse hyperbolic cosine, having domain
[+1, +infinity]
and codomain[+0, +infinity]
, for each elementx_i
of the input arrayx
.Special cases
For floating-point operands,
If
x_i
isNaN
, the result isNaN
.If
x_i
is less than1
, the result isNaN
.If
x_i
is1
, the result is+0
.If
x_i
is+infinity
, the result is+infinity
.
- Parameters
- Return type
- Returns
ret – an array containing the inverse hyperbolic cosine of each element in x. The returned array must have a floating-point data type determined by type-promotion.
Examples
With
ivy.Array
input: >>> x = ivy.array([1, 2.5, 10]) >>> y = ivy.acosh(x) >>> print(y) ivy.array([0. , 1.57, 2.99])>>> x = ivy.array([1., 2., 6.]) >>> y = ivy.zeros(3) >>> ivy.acosh(x, out=y) >>> print(y) ivy.array([0. , 1.32, 2.48])
With
ivy.NativeArray
input:>>> x = ivy.array([1., 2., 10.]) >>> y = ivy.acosh(x) >>> print(y) ivy.array([0. , 1.32, 2.99])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([1, 2, 10]), b=ivy.array([1., 10, 6])) >>> y = ivy.acosh(x) >>> print(y) { a: ivy.array([0., 1.32, 2.99]), b: ivy.array([0., 2.99, 2.48]) }
- ivy.add(x1, x2, /, *, out=None)[source]
Calculates the sum for each element
x1_i
of the input arrayx1
with the respective elementx2_i
of the input arrayx2
.Special cases
For floating-point operands,
If either
x1_i
orx2_i
isNaN
, the result isNaN
.If
x1_i
is+infinity
andx2_i
is-infinity
, the result isNaN
.If
x1_i
is-infinity
andx2_i
is+infinity
, the result isNaN
.If
x1_i
is+infinity
andx2_i
is+infinity
, the result is+infinity
.If
x1_i
is-infinity
andx2_i
is-infinity
, the result is-infinity
.If
x1_i
is+infinity
andx2_i
is a finite number, the result is+infinity
.If
x1_i
is-infinity
andx2_i
is a finite number, the result is-infinity
.If
x1_i
is a finite number andx2_i
is+infinity
, the result is+infinity
.If
x1_i
is a finite number andx2_i
is-infinity
, the result is-infinity
.If
x1_i
is-0
andx2_i
is-0
, the result is-0
.If
x1_i
is-0
andx2_i
is+0
, the result is+0
.If
x1_i
is+0
andx2_i
is-0
, the result is+0
.If
x1_i
is+0
andx2_i
is+0
, the result is+0
.If
x1_i
is either+0
or-0
andx2_i
is a nonzero finite number, the result isx2_i
.If
x1_i
is a nonzero finite number andx2_i
is either+0
or-0
, the result isx1_i
.If
x1_i
is a nonzero finite number andx2_i
is-x1_i
, the result is+0
.In the remaining cases, when neither
infinity
,+0
,-0
, nor aNaN
is involved, and the operands have the same mathematical sign or have different magnitudes, the sum must be computed and rounded to the nearest representable value according to IEEE 754-2019 and a supported round mode. If the magnitude is too large to represent, the operation overflows and the result is an infinity of appropriate mathematical sign.
Note
Floating-point addition is a commutative operation, but not always associative.
- Parameters
x1 (
Union
[float
,Array
,NativeArray
]) – first input array. Should have a numeric data type.x2 (
Union
[float
,Array
,NativeArray
]) – second input array. Must be compatible withx1
(see broadcasting). Should have a numeric data type.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
- Returns
ret – an array containing the element-wise sums. The returned array must have a data type determined by type-promotion.
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: >>> x = ivy.array([1, 2, 3]) >>> y = ivy.array([4, 5, 6]) >>> z = ivy.add(x, y) >>> print(z) ivy.array([5, 7, 9])>>> x = ivy.array([[1.1, 2.3, -3.6]]) >>> y = ivy.array([[4.8], [5.2], [6.1]]) >>> z = ivy.zeros((3, 3)) >>> ivy.add(x, y, out=z) >>> print(z) ivy.array([[5.9, 7.1, 1.2], [6.3, 7.5, 1.6], [7.2, 8.4, 2.5]])
>>> x = ivy.array([[[1.1], [3.2], [-6.3]]]) >>> y = ivy.array([[8.4], [2.5], [1.6]]) >>> ivy.add(x, y, out=x) >>> print(x) ivy.array([[[9.5], [5.7], [-4.7]]])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([1, 2, 3]), b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([4, 5, 6]), b=ivy.array([5, 6, 7])) >>> z = ivy.add(x, y) >>> print(z) { a: ivy.array([5, 7, 9]), b: ivy.array([7, 9, 11]) }
With a mix of
ivy.Array
andivy.Container
inputs:>>> x = ivy.array([[1.1, 2.3, -3.6]]) >>> y = ivy.Container(a=ivy.array([[4.], [5.], [6.]]), b=ivy.array([[5.], [6.], [7.]])) >>> z = ivy.add(x, y) >>> print(z) { a: ivy.array([[5.1, 6.3, 0.4], [6.1, 7.3, 1.4], [7.1, 8.3, 2.4]]), b: ivy.array([[6.1, 7.3, 1.4], [7.1, 8.3, 2.4], [8.1, 9.3, 3.4]]) }
- ivy.asin(x, /, *, out=None)[source]
Calculates an implementation-dependent approximation of the principal value of the inverse sine, having domain
[-1, +1]
and codomain[-π/2, +π/2]
for each elementx_i
of the input arrayx
. Each element-wise result is expressed in radians.Special cases
For floating-point operands,
If
x_i
isNaN
, the result isNaN
.If
x_i
is greater than1
, the result isNaN
.If
x_i
is less than-1
, the result isNaN
.If
x_i
is+0
, the result is+0
.If
x_i
is-0
, the result is-0
.
- Parameters
- Return type
- Returns
ret – an array containing the inverse sine of each element in
x
. The returned array must have a floating-point data type determined by type-promotion.This function conforms to the `Array API Standard
<https (//data-apis.org/array-api/latest/>`_. This docstring is an extension of the)
`docstring <https (//data-apis.org/array-api/latest/API_specification/generated/) – signatures.elementwise_functions.tan.html>`_
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.
Functional Examples
With
ivy.Array
input:>>> x = ivy.array([-2.4, -0, +0, 3.2, float('nan')]) >>> y = ivy.asin(x) >>> print(y) ivy.array([nan, 0., 0., nan, nan])
>>> x = ivy.array([-1, -0.5, 0.6, 1]) >>> y = ivy.zeros(4) >>> ivy.asin(x, out=y) >>> print(y) ivy.array([-1.57,-0.524,0.644,1.57])
>>> x = ivy.array([[0.1, 0.2, 0.3], [-0.4, -0.5, -0.6]]) >>> ivy.asin(x, out=x) >>> print(x) ivy.array([[0.1,0.201,0.305],[-0.412,-0.524,-0.644]])
With
ivy.NativeArray
input:>>> x = ivy.native_array([-1, -0.5, 0.6, 1]) >>> y = ivy.asin(x) >>> print(y) ivy.array([-1.57,-0.524,0.644,1.57])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([0., 0.1, 0.2]), b=ivy.array([0.3, 0.4, 0.5])) >>> y = ivy.asin(x) >>> print(y) {a:ivy.array([0.,0.1,0.201]),b:ivy.array([0.305,0.412,0.524])}
Instance Method Examples
Using
ivy.Array
instance method:>>> x = ivy.array([-1, -0.5, 0.6, 1]) >>> y = x.asin() >>> print(y) ivy.array([-1.57,-0.524,0.644,1.57])
Using
ivy.Container
instance method:>>> x = ivy.Container(a=ivy.array([0., 0.1, 0.2]), b=ivy.array([0.3, 0.4, 0.5])) >>> y = x.asin() >>> print(y) {a:ivy.array([0.,0.1,0.201]),b:ivy.array([0.305,0.412,0.524])}
- ivy.asinh(x, /, *, out=None)[source]
Calculates an implementation-dependent approximation to the inverse hyperbolic sine, having domain
[-infinity, +infinity]
and codomain[-infinity, +infinity]
, for each elementx_i
in the input arrayx
.Special cases
For floating-point operands,
If
x_i
isNaN
, the result isNaN
.If
x_i
is+0
, the result is+0
.If
x_i
is-0
, the result is-0
.If
x_i
is+infinity
, the result is+infinity
.If
x_i
is-infinity
, the result is-infinity
.
- Parameters
- Return type
- Returns
ret – an array containing the inverse hyperbolic sine of each element in
x
. The returned array must have a floating-point data type determined by type-promotion.This function conforms to the `Array API Standard
<https (//data-apis.org/array-api/latest/>`_. This docstring is an extension of the)
`docstring <https (//data-apis.org/array-api/latest/API_specification/generated/signatures.elementwise_functions.tan.html>`_ )
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
input:>>> x = ivy.array([-3.5, -0, +0, 1.3, float('nan')]) >>> y = ivy.asinh(x) >>> print(y) ivy.array([-1.97, 0., 0., 1.08, nan])
>>> x = ivy.array([-2, -0.75, 0.9, 1]) >>> y = ivy.zeros(4) >>> ivy.asinh(x, out=y) >>> print(y) ivy.array([-1.44, -0.693, 0.809, 0.881])
>>> x = ivy.array([[0.2, 0.4, 0.6], [-0.8, -1, -2]]) >>> ivy.asinh(x, out=x) >>> print(x) ivy.array([[ 0.199, 0.39, 0.569], [-0.733, -0.881, -1.44]])
With
ivy.NativeArray
input:>>> x = ivy.native_array([-0, -2.6, 1, 3.6]) >>> y = ivy.asinh(x) >>> print(y) ivy.array([ 0. , -1.68 , 0.881, 1.99 ])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([0., 1, 2]), b=ivy.array([4.2, -5.3, -0, -2.3])) >>> y = ivy.asinh(x) >>> print(y) { a: ivy.array([0., 0.881, 1.44]), b: ivy.array([2.14, -2.37, 0., -1.57]) }
- ivy.atan(x, /, *, out=None)[source]
Calculates an implementation-dependent approximation of the principal value of the inverse tangent, having domain
[-infinity, +infinity]
and codomain[-π/2, +π/2]
, for each elementx_i
of the input arrayx
. Each element-wise result is expressed in radians.Special cases
For floating-point operands,
If
x_i
isNaN
, the result isNaN
.If
x_i
is+0
, the result is+0
.If
x_i
is-0
, the result is-0
.If
x_i
is+infinity
, the result is an implementation-dependent approximation to+π/2
.If
x_i
is-infinity
, the result is an implementation-dependent approximation to-π/2
.
- Parameters
- Return type
- Returns
ret – an array containing the inverse tangent of each element in
x
. The returned array must have a floating-point data type determined by type-promotion.
Examples
With
ivy.Array
input: >>> x = ivy.array([0., 1., 2.]) >>> y = ivy.atan(x) >>> print(y) ivy.array([0. , 0.785, 1.11 ])>>> x = ivy.array([4., 0., -6.]) >>> y = ivy.zeros(3) >>> ivy.atan(x, out=y) >>> print(y) ivy.array([ 1.33, 0. , -1.41])
With
ivy.NativeArray
input:>>> x = ivy.array([1., 0., 2.]) >>> y = ivy.atan(x) >>> print(y) ivy.array([0.785, 0. , 1.11 ])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([0., -1, 1]), b=ivy.array([1., 0., -6])) >>> y = ivy.atan(x) >>> print(y) { a: ivy.array([0., -0.785, 0.785]), b: ivy.array([0.785, 0., -1.41]) }
- ivy.atan2(x1, x2, /, *, out=None)[source]
Calculates an implementation-dependent approximation of the inverse tangent of the quotient
x1/x2
, having domain[-infinity, +infinity] x. [-infinity, +infinity]
(where thex
notation denotes the set of ordered pairs of elements(x1_i, x2_i)
) and codomain[-π, +π]
, for each pair of elements(x1_i, x2_i)
of the input arraysx1
andx2
, respectively. Each element-wise result is expressed in radians. The mathematical signs ofx1_i and x2_i
determine the quadrant of each element-wise result. The quadrant (i.e., branch) is chosen such that each element-wise result is the signed angle in radians between the ray ending at the origin and passing through the point(1,0)
and the ray ending at the origin and passing through the point(x2_i, x1_i)
.Special cases
For floating-point operands,
If either
x1_i
orx2_i
isNaN
, the result isNaN
.If
x1_i
is greater than0
andx2_i
is+0
, the result is an approximation to+π/2
.If
x1_i
is greater than0
andx2_i
is-0
, the result is an approximation to+π/2
.If
x1_i
is+0
andx2_i
is greater than0
, the result is+0
.If
x1_i
is+0
andx2_i
is+0
, the result is+0
.If
x1_i
is+0
andx2_i
is-0
, the result is an approximation to+π
.If
x1_i
is+0
andx2_i
is less than 0, the result is an approximation to+π
.If
x1_i
is-0
andx2_i
is greater than0
, the result is-0
.If
x1_i
is-0
andx2_i
is+0
, the result is-0
.If
x1_i
is-0
andx2_i
is-0
, the result is an approximation to-π
.If
x1_i
is-0
andx2_i
is less than0
, the result is an approximation to-π
.If
x1_i
is less than0
andx2_i
is+0
, the result is an approximation to-π/2
.If
x1_i
is less than0
andx2_i
is-0
, the result is an approximation to-π/2
.If
x1_i
is greater than0
,x1_i
is a finite number, andx2_i
is+infinity
, the result is+0
.If
x1_i
is greater than0
,x1_i
is a finite number, andx2_i
is-infinity
, the result is an approximation to+π
.If
x1_i
is less than0
,x1_i
is a finite number, andx2_i
is+infinity
, the result is-0
.If
x1_i
is less than0
,x1_i
is a finite number, andx2_i
is-infinity
, the result is an approximation to-π
.If
x1_i
is+infinity
andx2_i
is finite, the result is an approximation to+π/2
.If
x1_i
is-infinity
andx2_i
is finite, the result is an approximation to-π/2
.If
x1_i
is+infinity
andx2_i
is+infinity
, the result is an approximation to+π/4
.If
x1_i
is+infinity
andx2_i
is-infinity
, the result is an approximation to+3π/4
.If
x1_i
is-infinity
andx2_i
is+infinity
, the result is an approximation to-π/4
.If
x1_i
is-infinity
andx2_i
is-infinity
, the result is an approximation to-3π/4
.
- Parameters
x1 (
Union
[Array
,NativeArray
]) – input array corresponding to the y-coordinates. Should have a floating-point data type.x2 (
Union
[Array
,NativeArray
]) – input array corresponding to the x-coordinates. Must be compatible withx1
. Should have a floating-point data type.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
- Returns
ret – an array containing the inverse tangent of the quotient
x1/x2
. The returned array must have a floating-point data type.This function conforms to the `Array API Standard
<https (//data-apis.org/array-api/latest/>`_. This docstring is an extension of the)
`docstring <https (//data-apis.org/array-api/latest/API_specification/generated/signatures.elementwise_functions.atan2.html>`_ )
in the standard.
The descriptions above assume an array input for simplicity, but
the method also accepts
ivy.Container
instances in place ofivy.Array
orivy.NativeArray
instances, as shown in the type hintsand also the examples below.
Examples
With
ivy.Array
input:>>> x = ivy.array([1.0, -1.0, -2.0]) >>> y = ivy.array([2.0, 0.0, 3.0]) >>> z = ivy.atan2(x, y) >>> print(z) ivy.array([ 0.464, -1.57 , -0.588])
>>> x = ivy.array([1.0, 2.0]) >>> y = ivy.array([-2.0, 3.0]) >>> z = ivy.zeros(2) >>> x.atan2(y, out=z) >>> print(z) ivy.array([2.68 , 0.588])
>>> nan = float("nan") >>> x = ivy.array([nan, 1.0, 1.0, -1.0, -1.0]) >>> y = ivy.array([1.0, +0, -0, +0, -0]) >>> x.atan2(y) ivy.array([ nan, 1.57, 1.57, -1.57, -1.57])
>>> x = ivy.array([+0, +0, +0, +0, -0, -0, -0, -0]) >>> y = ivy.array([1.0, +0, -0, -1.0, 1.0, +0, -0, -1.0]) >>> x.atan2(y) ivy.array([0. , 0. , 0. , 3.14, 0. , 0. , 0. , 3.14]) >>> y.atan2(x) ivy.array([ 1.57, 0. , 0. , -1.57, 1.57, 0. , 0. , -1.57])
>>> inf = float("infinity") >>> x = ivy.array([inf, -inf, inf, inf, -inf, -inf]) >>> y = ivy.array([1.0, 1.0, inf, -inf, inf, -inf]) >>> z = x.atan2(y) >>> print(z) ivy.array([ 1.57 , -1.57 , 0.785, 2.36 , -0.785, -2.36 ])
>>> x = ivy.array([2.5, -1.75, 3.2, 0, -1.0]) >>> y = ivy.array([-3.5, 2, 0, 0, 5]) >>> z = x.atan2(y) >>> print(z) ivy.array([ 2.52 , -0.719, 1.57 , 0. , -0.197])
>>> x = ivy.array([[1.1, 2.2, 3.3], [-4.4, -5.5, -6.6]]) >>> y = x.atan2(x) >>> print(y) ivy.array([[ 0.785, 0.785, 0.785], [-2.36 , -2.36 , -2.36 ]])
With
ivy.NativeArray
input:>>> x = ivy.native_array([0, -0, -2.6, -1, 1, 3.6]) >>> y = ivy.native_array([-1.1, 2.5, -2.0, 1.0, 5.0, -2.5]) >>> z = ivy.atan2(x, y) >>> print(z) ivy.array([ 3.14 , 0. , -2.23 , -0.785, 0.197, 2.18 ])
With
ivy.Container
input: >>> x = ivy.Container(a=ivy.array([0., 2.6, -3.5]), b=ivy.array([4.5, -5.3, -0])) >>> y = ivy.array([3.0, 2.0, 1.0]) >>> x.atan2(y) {a: ivy.array([0., 0.915, -1.29]), b: ivy.array([0.983, -1.21, 0.])
}
>>> x = ivy.Container(a=ivy.array([0., 2.6, -3.5]), b=ivy.array([4.5, -5.3, -0, -2.3])) >>> y = ivy.Container(a=ivy.array([-2.5, 1.75, 3.5]), b=ivy.array([2.45, 6.35, 0, 1.5])) >>> z = x.atan2(y) >>> print(z) { a: ivy.array([3.14, 0.978, -0.785]), b: ivy.array([1.07, -0.696, 0., -0.993]) }
- ivy.atanh(x, /, *, out=None)[source]
Returns a new array with the inverse hyperbolic tangent of the elements of
x
.- Parameters
- Return type
- Returns
ret – an array containing the inverse hyperbolic tangent of each element in
x
. The returned array must have a floating-point data type determined by Type Promotion Rules.
Examples
With
ivy.Array
input: >>> x = ivy.array([0, -0.5]) >>> y = ivy.atanh(x) >>> print(y) ivy.array([ 0. , -0.549])>>> x = ivy.array([0.5, -0.5, 0.]) >>> y = ivy.zeros(3) >>> ivy.atanh(x, out=y) >>> print(y) ivy.array([ 0.549, -0.549, 0. ])
With
ivy.NativeArray
input:>>> x = ivy.array([ 0., 0.5]) >>> y = ivy.atanh(x) >>> print(y) ivy.array([0. , 0.549])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([0., -0.5]), b=ivy.array([ 0., 0.5])) >>> y = ivy.atanh(x) >>> print(y) { a: ivy.array([0., -0.549]), b: ivy.array([0., 0.549]) }
- ivy.bitwise_and(x1, x2, /, *, out=None)[source]
Computes the bitwise AND of the underlying binary representation of each element
x1_i
of the input arrayx1
with the respective elementx2_i
of the input arrayx2
.- Parameters
x1 (
Union
[int
,bool
,Array
,NativeArray
]) – first input array. Should have an integer or boolean data type.x2 (
Union
[int
,bool
,Array
,NativeArray
]) – second input array. Must be compatible withx1
(see broadcasting). Should have an integer or boolean data type.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
- Returns
ret – an array containing the element-wise results. The returned array must have a data type determined by type-promotion.
This function conforms to the Array API Standard. This docstring is an extension of the docstring in the standard. The descriptions above assume an array input for simplicity, but the method also accepts
ivy.Container
instances in place ofivy.Array
orivy.NativeArray
instances, as shown in the type hints and also the examples below.Functional Examples
With
ivy.Array
inputs:>>> x = ivy.array([2, 3, 7]) >>> y = ivy.array([7, 1, 15]) >>> z = ivy.bitwise_and(x, y) >>> print(z) ivy.array([2, 1, 7])
>>> x = ivy.array([[True], [False]]) >>> y = ivy.array([[True], [True]]) >>> ivy.bitwise_and(x, y, out=x) >>> print(x) ivy.array([[ True], [False]])
>>> x = ivy.array([1]) >>> y = ivy.array([3]) >>> ivy.bitwise_and(x, y, out=y) >>> print(y) ivy.array([1])
With
ivy.NativeArray
inputs:>>> x = ivy.native_array([True, True, False, False]) >>> y = ivy.native_array([True, False, True, False]) >>> ivy.bitwise_and(x, y, out=y) >>> print(y) tensor([True,False,False,False])
>>> x = ivy.native_array([[True, False]]) >>> y = ivy.native_array([[True], [False]]) >>> z = ivy.bitwise_and(x, y) >>> print(z) ivy.array([[ True, False], [False, False]])
With a mix of
ivy.Array
andivy.NativeArray
inputs:>>> x = ivy.array([[6, 5], [3, 7]]) >>> y = ivy.native_array([[2, 11], [9, 13]]) >>> z = ivy.bitwise_and(x, y) >>> print(z) ivy.array([[2, 1], [1, 5]])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([1, 2, 3]), b=ivy.array([4, 5, 6])) >>> y = ivy.Container(a=ivy.array([7, 8, 9]), b=ivy.array([10, 11, 11])) >>> z = ivy.bitwise_and(x, y) >>> print(z) { a: ivy.array([1, 0, 1]), b: ivy.array([0, 1, 2]) }
With a mix of
ivy.Array
andivy.Container
inputs:>>> x = ivy.array([True, True]) >>> y = ivy.Container(a=ivy.array([True, False]), b=ivy.array([False, True])) >>> z = ivy.bitwise_and(x, y) >>> print(z) { a: ivy.array([True, False]), b: ivy.array([False, True]) }
Instance Method Examples
Using
ivy.Array
instance method:>>> x = ivy.array([True, False]) >>> y = ivy.array([True, True]) >>> x.bitwise_and(y, out=y) >>> print(y) ivy.array([ True, False])
>>> x = ivy.array([[7], [8], [9]]) >>> y = ivy.native_array([[10], [11], [12]]) >>> z = x.bitwise_and(y) >>> print(z) ivy.array([[2], [8], [8]])
Using
ivy.Container
instance method:>>> x = ivy.Container(a=ivy.array([True, True]), b=ivy.array([False, True])) >>> y = ivy.Container(a=ivy.array([False, True]), b=ivy.array([False, True])) >>> x.bitwise_and(y, out=y) >>> print(y) { a: ivy.array([False, True]), b: ivy.array([False, True]) }
- ivy.bitwise_invert(x, /, *, out=None)[source]
Inverts (flips) each bit for each element
x_i
of the input arrayx
.- Parameters
- Return type
- Returns
ret – an array containing the element-wise results. The returned array must have the same data type as x.
Examples
>>> x = ivy.array([1, 6, 9]) >>> y = ivy.bitwise_invert(x) >>> print(y) ivy.array([-2, -7, -10])
- ivy.bitwise_left_shift(x1, x2, /, *, out=None)[source]
Shifts the bits of each element
x1_i
of the input arrayx1
to the left by appendingx2_i
(i.e., the respective element in the input arrayx2
) zeros to the right ofx1_i
.- Parameters
x1 (
Union
[int
,Array
,NativeArray
]) – first input array. Should have an integer data type.x2 (
Union
[int
,Array
,NativeArray
]) – second input array. Must be compatible withx1
(see broadcasting). Should have an integer data type. Each element must be greater than or equal to0
.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
- Returns
ret – an array containing the element-wise results. The returned array must have a data type determined by type-promotion.
- ivy.bitwise_or(x1, x2, /, *, out=None)[source]
Computes the bitwise OR of the underlying binary representation of each element
x1_i
of the input arrayx1
with the respective elementx2_i
of the input arrayx2
.- Parameters
x1 (
Union
[int
,bool
,Array
,NativeArray
]) – first input array. Should have an integer or boolean data type.x2 (
Union
[int
,bool
,Array
,NativeArray
]) – second input array. Must be compatible withx1
(see broadcasting). Should have an integer or boolean data type.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
- Returns
ret – an array containing the element-wise results. The returned array must have a data type determined by type-promotion.
Examples
With
ivy.Array
inputs: >>> x = ivy.array([1, 2, 3]) >>> y = ivy.array([4, 5, 6]) >>> z = ivy.bitwise_or(x, y) >>> print(z) ivy.array([5, 7, 7])>>> x = ivy.array([[[1], [2], [3], [4]]]) >>> y = ivy.array([[[4], [5], [6], [7]]]) >>> ivy.bitwise_or(x, y, out=x) >>> print(x) ivy.array([[[5], [7], [7], [7]]])
>>> x = ivy.array([[[1], [2], [3], [4]]]) >>> y = ivy.array([4, 5, 6, 7]) >>> z = ivy.bitwise_or(x, y) >>> print(z) ivy.array([[[5, 5, 7, 7], [6, 7, 6, 7], [7, 7, 7, 7], [4, 5, 6, 7]]])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([1, 2, 3]), b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([4, 5, 6]), b=ivy.array([5, 6, 7])) >>> z = ivy.bitwise_or(x, y) >>> print(z) { a: ivy.array([5, 7, 7]), b: ivy.array([7, 7, 7]) }
With a mix of
ivy.Array
andivy.Container
inputs:>>> x = ivy.array([1, 2, 3]) >>> y = ivy.Container(a=ivy.array([4, 5, 6]), b=ivy.array([5, 6, 7])) >>> z = ivy.bitwise_or(x, y) >>> print(z) { a: ivy.array([5,7,7]), b: ivy.array([5,6,7]) }
- ivy.bitwise_right_shift(x1, x2, /, *, out=None)[source]
Shifts the bits of each element
x1_i
of the input arrayx1
to the right according to the respective elementx2_i
of the input arrayx2
.Note
This operation must be an arithmetic shift (i.e., sign-propagating) and thus equivalent to floor division by a power of two.
- Parameters
x1 (
Union
[int
,Array
,NativeArray
]) – first input array. Should have an integer data type.x2 (
Union
[int
,Array
,NativeArray
]) – second input array. Must be compatible withx1
(see ref:broadcasting). Should have an integer data type. Each element must be greater than or equal to 0.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
- Returns
ret – out (array), an array containing the element-wise results. The returned array must have a data type determined by Type Promotion Rules.
Examples
>>> lhs = ivy.array([5, 2, 3, 1], dtype=ivy.int64) >>> rhs = ivy.array([1, 3, 2, 1], dtype=ivy.int64) >>> y = ivy.bitwise_right_shift(lhs, rhs) >>> print(y) ivy.array([2, 0, 0, 0])
- ivy.bitwise_xor(x1, x2, /, *, out=None)[source]
Computes the bitwise XOR of the underlying binary representation of each element
x1_i
of the input arrayx1
with the respective elementx2_i
of the input arrayx2
.Special cases
This function does not take floating point operands
- Parameters
x1 (
Union
[int
,bool
,Array
,NativeArray
]) – first input array. Should have an integer or boolean data type.x2 (
Union
[int
,bool
,Array
,NativeArray
]) – second input array. Must be compatible withx1
(see broadcasting). Should have an integer or boolean data type.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
- Returns
ret – an array containing the element-wise results. The returned array must have a data type determined by type-promotion.
This function conforms to the `Array API Standard
<https (//data-apis.org/array-api/latest/>`_. This docstring is an extension of the)
`docstring <https (//data-apis.org/array-api/latest/API_specification/generated/signatures.elementwise_functions.bitwise_xor.html>`_ )
in the standard. The descriptions above assume an array input for simplicity, but
the method also accepts
ivy.Container
instances in place ofivy.Array
orivy.NativeArray
instances, as shown in the type hintsand also the examples below.
Functional Examples
With
ivy.Array
input:>>> a = ivy.array([1, 2, 3]) >>> b = ivy.array([3, 2, 1]) >>> y = ivy.bitwise_xor(a, b) >>> print(y) ivy.array([2, 0, 2])
>>> a = ivy.array([78, 91, 23]) >>> b = ivy.array([66, 77, 88]) >>> ivy.bitwise_xor(a, b, out=y) >>> print(y) ivy.array([12, 22, 79])
>>> a = ivy.array([1, 2, 3]) >>> b = ivy.array([3, 2, 1]) >>> ivy.bitwise_xor(a, b, out = a) >>> print(a) ivy.array([2, 0, 2])
With :code: ivy.NativeArray input:
>>> a = ivy.native_array([0, 1, 3, 67, 91]) >>> b = ivy.native_array([4, 7, 90, 89, 98]) >>> y = ivy.bitwise_xor(a, b) >>> print(y) ivy.array([ 4, 6, 89, 26, 57])
With a mix of :code: ivy.Array and
ivy.NativeArray
inputs:>>> a = ivy.array([0, 1, 3, 67, 91]) >>> a = ivy.native_array([4, 7, 90, 89, 98]) >>> y = ivy.bitwise_xor(a, b) >>> print(y) ivy.array([0,0,0,0,0])
With :code: ivy.Container input:
>>> x = ivy.Container(a = ivy.array([89])) >>> b = ivy.array([90]) >>> y = ivy.Container(a = ivy.array([12])) >>> b = ivy.array([78]) >>> z = ivy.bitwise_xor(x, y) >>> print(z) { a:ivy.array([85]) }
With a mix of
ivy.Array
andivy.Container
inputs:>>> x = ivy.Container(a = ivy.array([-67, 21])) >>> b = ivy.array([78, 34]) >>> y = ivy.array([12, 13]) >>> z = ivy.bitwise_xor(x, y) >>> print(z) { a: ivy.array([-79, 24]) }
Instance Method Examples
Using :code: ivy.Array instance method:
>>> a = ivy.array([[89, 51, 32], [14, 18, 19]]) >>> b = ivy.array([[[19, 26, 27], [22, 23, 20]]]) >>> y = a.bitwise_xor(b) >>> print(y) ivy.array([[[74,41,59],[24,5,7]]])
Using
ivy.Container
instance method:>>> x = ivy.Container(a = ivy.array([89])) >>> b = ivy.array([90]) >>> y = ivy.Container(a = ivy.array([12])) >>> b = ivy.array([78]) >>> z = x.bitwise_xor(y) >>> print(z) {a:ivy.array([85])}
Operator Examples
With
ivy.Array
instances:>>> a = ivy.array([1, 2, 3]) >>> b = ivy.array([3, 2, 1]) >>> y = a ^ b >>> print(y) ivy.array([2,0,2])
With
ivy.Container
instances:>>> x = ivy.Container(a = ivy.array([89])) >>> b = ivy.array([90]) >>> y = ivy.Container(a = ivy.array([12])) >>> b = ivy.array([78]) >>> z = x ^ y >>> print(z) {a:ivy.array([85])}
With mix of
ivy.Array
andivy.Container
instances:>>> x = ivy.Container(a = ivy.array([-67, 21])) >>> b = ivy.array([78, 34]) >>> y = ivy.array([12, 13]) >>> z = x ^ y >>> print(z) {a: ivy.array([-79, 24])}
- ivy.ceil(x, /, *, out=None)[source]
Rounds each element
x_i
of the input arrayx
to the smallest (i.e., closest to-infinity
) integer-valued number that is not less thanx_i
.Special cases
If
x_i
is already integer-valued, the result isx_i
.
For floating-point operands,
If
x_i
is+infinity
, the result is+infinity
.If
x_i
is-infinity
, the result is-infinity
.If
x_i
is+0
, the result is+0
.If
x_i
is-0
, the result is-0
.If
x_i
isNaN
, the result isNaN
.
- Parameters
- Return type
- Returns
ret – an array containing the rounded result for each element in
x
. The returned array must have the same data type asx
.This method conforms to the
`Array API Standard <https (//data-apis.org/array-api/latest/>`_.)
This docstring is an extension of the
`docstring <https (//data-apis.org/array-api/latest/API_specification/generated/signatures.elementwise_functions.ceil.html>`_ )
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
input:>>> x = ivy.array([0.1, 0, -0.1]) >>> y = ivy.ceil(x) >>> print(y) ivy.array([1., 0., -0.])
>>> x = ivy.array([2.5, -3.5, 0, -3, -0]) >>> y = ivy.ones(5) >>> ivy.ceil(x, out=y) >>> print(y) ivy.array([ 3., -3., 0., -3., 0.])
>>> x = ivy.array([[3.3, 4.4, 5.5], [-6.6, -7.7, -8.8]]) >>> ivy.ceil(x, out=x) >>> print(x) ivy.array([[ 4., 5., 6.], [-6., -7., -8.]])
With
ivy.NativeArray
input:>>> x = ivy.native_array([0, -0, -2.5, -1, 2, 3.5]) >>> y = ivy.ceil(x) >>> print(y) ivy.array([ 0., 0., -2., -1., 2., 4.])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([2.5, 0.5, -1.4]), b=ivy.array([5.4, -3.2, -0, 5.2])) >>> y = ivy.ceil(x) >>> print(y) { a: ivy.array([3., 1., -1.]), b: ivy.array([6., -3., 0., 6.]) }
- ivy.cos(x, /, *, out=None)[source]
Calculates an implementation-dependent approximation to the cosine, having domain
(-infinity, +infinity)
and codomain[-1, +1]
, for each elementx_i
of the input arrayx
. Each elementx_i
is assumed to be expressed in radians.Special cases
For floating-point operands,
If
x_i
isNaN
, the result isNaN
.If
x_i
is+0
, the result is1
.If
x_i
is-0
, the result is1
.If
x_i
is+infinity
, the result isNaN
.If
x_i
is-infinity
, the result isNaN
.
- Parameters
- Return type
- Returns
ret – an array containing the cosine of each element in
x
. The returned array must have a floating-point data type determined by type-promotion.
Examples
With
ivy.Array
input:>>> x = ivy.array([0., 1., 2.]) >>> y = ivy.cos(x) >>> print(y) ivy.array([1., 0.54, -0.416])
>>> x = ivy.array([4., 0., -6.]) >>> y = ivy.zeros(3) >>> ivy.cos(x, out=y) >>> print(y) ivy.array([-0.654, 1., 0.96])
With
ivy.NativeArray
input:>>> x = ivy.array([1., 0., 2.]) >>> y = ivy.cos(x) >>> print(y) ivy.array([0.54 , 1., -0.416])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([0., -1, 1]), b=ivy.array([1., 0., -6])) >>> y = ivy.cos(x) >>> print(y) { a: ivy.array([1., 0.54, 0.54]), b: ivy.array([0.54, 1., 0.96]) }
- ivy.cosh(x, /, *, out=None)[source]
Calculates an implementation-dependent approximation to the hyperbolic cosine, having domain
[-infinity, +infinity]
and codomain[-infinity, +infinity]
, for each elementx_i
in the input arrayx
.Special cases
For floating-point operands,
If
x_i
isNaN
, the result isNaN
.If
x_i
is+0
, the result is1
.If
x_i
is-0
, the result is1
.If
x_i
is+infinity
, the result is+infinity
.If
x_i
is-infinity
, the result is+infinity
.
- Parameters
- Return type
- Returns
ret – an array containing the hyperbolic cosine of each element in
x
. The returned array must have a floating-point data type determined by type-promotion.This function conforms to the `Array API Standard
<https (//data-apis.org/array-api/latest/>`_. This docstring is an extension of the)
`docstring <https (//data-apis.org/array-api/latest/API_specification/generated/signatures.elementwise_functions.cosh.html>`_ )
in the standard. The descriptions above assume an array input for simplicity, but
the method also accepts
ivy.Container
instances in place ofivy.Array
orivy.NativeArray
instances, as shown in the type hintsand also the examples below.
Functional Examples
With
ivy.Array
input:>>> x = ivy.array([1, 2, 3, 4]) >>> y = ivy.cosh(x) >>> print(y) ivy.array([1.54,3.76,10.1,27.3])
>>> x = ivy.array([0.2, -1.7, -5.4, 1.1]) >>> y = ivy.zeros(4) >>> ivy.cosh(x, out=y) ivy.array([[1.67,4.57,13.6,12.3],[40.7,122.,368.,670.]])
>>> x = ivy.array([[1.1, 2.2, 3.3, 3.2], [-4.4, -5.5, -6.6, -7.2]]) >>> y = ivy.cosh(x) >>> print(y) ivy.array([[1.67,4.57,13.6,12.3],[40.7,122.,368.,670.]])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([1., 2., 3.]), b=ivy.array([6., 7., 8.])) >>> y = ivy.cosh(x) >>> print(y) {a:ivy.array([1.54,3.76,10.1]),b:ivy.array([202.,548.,1490.])}
Instance Method Examples
Using
ivy.Array
instance method:>>> x = ivy.array([1., 2., 3.]) >>> y = x.cosh() >>> print(y) ivy.array([1.54,3.76,10.1])
>>> x = ivy.Container(a=ivy.array([1., 2., 3.]), b=ivy.array([6., 7., 8.])) >>> y = x.cosh() >>> print(y) {a:ivy.array([1.54,3.76,10.1]),b:ivy.array([202.,548.,1490.])}
- ivy.divide(x1, x2, /, *, out=None)[source]
Calculates the division 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
]) – dividend input array. Should have a numeric data type.x2 (
Union
[float
,Array
,NativeArray
]) – divisor input array. Must be compatible with x1 (see Broadcasting). Should have a numeric data type.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
- Returns
ret – an array containing the element-wise results. The returned array must have a floating-point data type determined by Type Promotion Rules.
Examples
With
ivy.Array
inputs:>>> x1 = ivy.array([2., 7., 9.]) >>> x2 = ivy.array([3., 4., 0.6]) >>> y = ivy.divide(x1, x2) >>> print(y) ivy.array([0.667, 1.75, 15.])
With
ivy.NativeArray
inputs:>>> x1 = ivy.native_array([2., 7., 9.]) >>> x2 = ivy.native_array([2., 2., 2.]) >>> y = ivy.divide(x1, x2) >>> print(y) ivy.array([1., 3.5, 4.5])
With mixed
ivy.Array
andivy.NativeArray
inputs:>>> x1 = ivy.array([5., 6., 9.]) >>> x2 = ivy.native_array([2., 2., 2.]) >>> y = ivy.divide(x1, x2) >>> print(y) ivy.array([2.5, 3., 4.5])
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([1., 2.3, 3]), b=ivy.array([2.4, 3., 2.])) >>> y = ivy.divide(x1, x2) >>> print(y) { a: ivy.array([12., 1.52, 2.1]), b: ivy.array([1.25, 0.333, 0.45]) }
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([4.3, 3., 5.]) >>> y = ivy.divide(x1, x2) { a: ivy.array([2.79, 1.17, 1.26]), b: ivy.array([0.698, 0.333, 0.18]) }
- ivy.equal(x1, x2, /, *, out=None)[source]
Computes 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
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
- 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 = ivy.equal(x1, x2) >>> print(y) ivy.array([False, True, True])
With
ivy.NativeArray
inputs:>>> x1 = ivy.native_array([2.5, 7.3, 9.375]) >>> x2 = ivy.native_array([2.5, 2.9, 9.375]) >>> y = ivy.equal(x1, x2) >>> print(y) ivy.array([True, False, 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]) }
- ivy.erf(x, /, *, out=None)[source]
Computes the Gauss error function of
x
element-wise.- Parameters
- Return type
Union
[Array
,NativeArray
]- Returns
ret – The Gauss error function of x.
- ivy.exp(x, /, *, out=None)[source]
Calculates an implementation-dependent approximation to the exponential function, having domain
[-infinity, +infinity]
and codomain[+0, +infinity]
, for each elementx_i
of the input arrayx
(e
raised to the power ofx_i
, wheree
is the base of the natural logarithm).Special cases
For floating-point operands,
If
x_i
isNaN
, the result isNaN
.If
x_i
is+0
, the result is1
.If
x_i
is-0
, the result is1
.If
x_i
is+infinity
, the result is+infinity
.If
x_i
is-infinity
, the result is+0
.
- Parameters
- Return type
- Returns
ret – an array containing the evaluated exponential function result for each element in
x
. The returned array must have a floating-point data type determined by type-promotion.
Examples
>>> x = ivy.array([1., 2., 3.]) >>> y = ivy.exp(x) >>> print(y) ivy.array([2.72,7.39,20.1])
- ivy.expm1(x, /, *, out=None)[source]
Calculates an implementation-dependent approximation to
exp(x)-1
, having domain[-infinity, +infinity]
and codomain[-1, +infinity]
, for each elementx_i
of the input arrayx
.Note
The purpose of this function is to calculate
exp(x)-1.0
more accurately whenx
is close to zero. Accordingly, conforming implementations should avoid implementing this function as simplyexp(x)-1.0
. See FDLIBM, or some other IEEE 754-2019 compliant mathematical library, for a potential reference implementation.Special cases
For floating-point operands,
If
x_i
isNaN
, the result isNaN
.If
x_i
is+0
, the result is+0
.If
x_i
is-0
, the result is-0
.If
x_i
is+infinity
, the result is+infinity
.If
x_i
is-infinity
, the result is-1
.
- Parameters
- Return type
- Returns
ret – an array containing the evaluated result for each element in
x
. The returned array must have a floating-point data type determined by type-promotion.This function conforms to the `Array API Standard
<https (//data-apis.org/array-api/latest/>`_. This docstring is an extension of the)
`docstring <https (//data-apis.org/array-api/latest/API_specification/generated/signatures.elementwise_functions.expm1.html>`_ )
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:>>> x = ivy.array([[0, 5, float('-0'), ivy.nan]]) >>> ivy.expm1(x) ivy.array([[ 0., 147., -0., nan]])
>>> x = ivy.array([ivy.inf, 1, float('-inf')]) >>> y = ivy.zeros(3) >>> ivy.expm1(x, out=y) ivy.array([ inf, 1.72, -1. ])
With
ivy.NativeArray
inputs:>>> x = ivy.native_array([[1], [5], [-ivy.inf]]) >>> ivy.expm1(x) ivy.array([[ 1.72], [147. ], [ -1. ]])
With
ivy.Array
instance method:>>> x = ivy.array([20]) >>> x.expm1() ivy.array([4.85e+08])
With
ivy.Container
inputs:>>> x = ivy.Container(a=ivy.array([-1, 0,]), b=ivy.array([10, 1])) >>> ivy.expm1(x) { a: ivy.array([-0.632, 0.]), b: ivy.array([2.20e+04, 1.72e+00]) }
With
ivy.Container
instance method:>>> x = ivy.Container(a=ivy.array([10, 13])) >>> x.expm1(x) { a: ivy.array([22000., 442000.]) }
With
ivy.Container
static method:>>> x = ivy.Container(a=ivy.array([1])) >>> ivy.Container.static_expm1(x) { a: ivy.array([1.72]) }
- ivy.floor(x, /, *, out=None)[source]
Rounds each element
x_i
of the input arrayx
to the greatest (i.e., closest to+infinity
) integer-valued number that is not greater thanx_i
.Special cases
If
x_i
is already integer-valued, the result isx_i
.
For floating-point operands,
If
x_i
is+infinity
, the result is+infinity
.If
x_i
is-infinity
, the result is-infinity
.If
x_i
is+0
, the result is+0
.If
x_i
is-0
, the result is-0
.If
x_i
isNaN
, the result isNaN
.
- Parameters
- Return type
- Returns
ret – an array containing the rounded result for each element in
x
. The returned array must have the same data type asx
.This method conforms to the
`Array API Standard<https (//data-apis.org/array-api/latest/>`_.)
This docstring is an extension of the
`docstring <https (//data-apis.org/array-api/latest/API_specification/)
generated/signatures.elementwise_functions.floor.html>`_ 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.
Functional Examples
With
ivy.Array
input:>>> x = ivy.array([2,3,4]) >>> y = ivy.floor(x) >>> print(y) ivy.array([2, 3, 4])
>>> x = ivy.array([1.5, -5.5, 0, -1, -0]) >>> y = ivy.zeros(5) >>> ivy.floor(x, out=y) >>> print(y) ivy.array([ 1., -6., 0., -1., 0.])
>>> x = ivy.array([[1.1, 2.2, 3.3], [-4.4, -5.5, -6.6]]) >>> ivy.floor(x, out=x) >>> print(x) ivy.array([[ 1., 2., 3.], [-5., -6., -7.]])
With
ivy.NativeArray
input:>>> x = ivy.native_array([0, -0, -1.5, -1, 1, 2.5]) >>> y = ivy.floor(x) >>> print(y) ivy.array([ 0., 0., -2., -1., 1., 2.])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([0., 1.5, -2.4]), b=ivy.array([3.4, -4.2, -0, -1.2])) >>> y = ivy.floor(x) >>> print(y) { a: ivy.array([0., 1., -3.]), b: ivy.array([3., -5., 0., -2.]) }
- ivy.floor_divide(x1, x2, /, *, out=None)[source]
Rounds the result of dividing each element x1_i of the input array x1 by the respective element x2_i of the input array x2 to the greatest (i.e., closest to +infinity) integer-value number that is not greater than the division result.
- Parameters
x1 (
Union
[float
,Array
,NativeArray
]) – first input array. Must have a numeric data type.x2 (
Union
[float
,Array
,NativeArray
]) – second input array. Must be compatible with x1 (with Broadcasting). Must have a numeric data type.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
- Returns
ret – an array containing the element-wise results. The returned array must have a numeric data type.
Examples
With
ivy.Array
inputs:>>> x1 = ivy.array([13., 7., 8.]) >>> x2 = ivy.array([3., 2., 7.]) >>> y = ivy.floor_divide(x1, x2) >>> print(y) ivy.array([4., 3., 1.])
With
ivy.NativeArray
inputs:>>> x1 = ivy.native_array([3., 4., 5.]) >>> x2 = ivy.native_array([5., 2., 1.]) >>> y = ivy.floor_divide(x1, x2) >>> print(y) ivy.array([0., 2., 5.])
With mixed
ivy.Array
andivy.NativeArray
inputs:>>> x1 = ivy.array([3., 4., 5.]) >>> x2 = ivy.native_array([5., 2., 1.]) >>> y = ivy.floor_divide(x1, x2) >>> print(y) ivy.array([0., 2., 5.])
With
ivy.Container
inputs:>>> x1 = ivy.Container(a=ivy.array([4., 5., 6.]), b=ivy.array([7., 8., 9.])) >>> x2 = ivy.Container(a=ivy.array([5., 4., 2.5]), b=ivy.array([2.3, 3.7, 5])) >>> y = ivy.floor_divide(x1, x2) >>> print(y) { a: ivy.array([0., 1., 2.]), b: ivy.array([3., 2., 1.]) }
With mixed
ivy.Container
andivy.Array
inputs:>>> x1 = ivy.Container(a=ivy.array([4., 5., 6.]), b=ivy.array([7., 8., 9.])) >>> x2 = ivy.array([2., 2., 2.]) >>> y = ivy.floor_divide(x1, x2) >>> print(y) { a: ivy.array([2., 2., 3.]), b: ivy.array([3., 4., 4.]) }
- ivy.greater(x1, x2, /, *, out=None)[source]
Computes 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
- Return type
- Returns
ret – an array containing the element-wise results. The returned array must have a data type of bool.
Examples
With
ivy.Array
input:>>> x = ivy.greater(ivy.array([1,2,3]),ivy.array([2,2,2])) >>> print(x) ivy.array([False, False, True])
>>> x = ivy.array([[[1.1], [3.2], [-6.3]]]) >>> y = ivy.array([[8.4], [2.5], [1.6]]) >>> ivy.greater(x, y, out=x) >>> print(x) ivy.array([[[0.],[1.],[0.]]])
With
ivy.NativeArray
input:>>> x = ivy.native_array([1, 2]) >>> y = ivy.native_array([4, 5]) >>> z = ivy.greater(x, y) >>> print(z) ivy.array([False,False])
With a mix of
ivy.Array
andivy.NativeArray
inputs:>>> x = ivy.array([1, 2, 3]) >>> y = ivy.native_array([4, 5, 0]) >>> z = ivy.greater(x, y) >>> print(z) ivy.array([False,False,True])
With a mix of
ivy.Array
andivy.Container
inputs:>>> x = ivy.array([[5.1, 2.3, -3.6]]) >>> y = ivy.Container(a=ivy.array([[4.], [5.], [6.]]), b=ivy.array([[5.], [6.], [7.]])) >>> z = ivy.greater(x, y) >>> print(z) { a: ivy.array([[True, False, False], [True, False, False], [False, False, False]]), b: ivy.array([[True, False, False], [False, False, False], [False, False, False]]) }
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([4, 5, 6]), b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([1, 2, 3]), b=ivy.array([5, 6, 7])) >>> z = ivy.greater(x, y) >>> print(z) { a: ivy.array([True, True, True]), b: ivy.array([False, False, False]) }
- ivy.greater_equal(x1, x2, /, *, out=None)[source]
Computes 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
]) – first input array. May have any data type.x2 (
Union
[float
,Array
,NativeArray
]) – second input array. Must be compatible with x1 (with Broadcasting). May have any data type.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
- Returns
ret – an array containing the element-wise results. The returned array must have a data type of bool.
Functional Examples
With
ivy.Array
input:>>> x = ivy.greater_equal(ivy.array([1,2,3]),ivy.array([2,2,2])) >>> print(x) ivy.array([False,True,True])
>>> x = ivy.array([[10.1, 2.3, -3.6]]) >>> y = ivy.array([[4.8], [5.2], [6.1]]) >>> shape = (3,3) >>> fill_value = False >>> z = ivy.full(shape, fill_value) >>> ivy.greater_equal(x, y, out=z) >>> print(z) ivy.array([[True,False,False],[True,False,False],[True,False,False]])
>>> x = ivy.array([[[1.1], [3.2], [-6.3]]]) >>> y = ivy.array([[8.4], [2.5], [1.6]]) >>> ivy.greater_equal(x, y, out=x) >>> print(x) ivy.array([[[0.],[1.],[0.]]])
With
ivy.NativeArray
input:>>> x = ivy.native_array([1, 2]) >>> y = ivy.native_array([4, 5]) >>> z = ivy.greater_equal(x, y) >>> print(z) ivy.array([False,False])
With a mix of
ivy.Array
andivy.NativeArray
inputs:>>> x = ivy.array([1, 2, 3]) >>> y = ivy.native_array([4, 5, 0]) >>> z = ivy.greater_equal(x, y) >>> print(z) ivy.array([False,False,True])
With a mix of
ivy.Array
andivy.Container
inputs:>>> x = ivy.array([[5.1, 2.3, -3.6]]) >>> y = ivy.Container(a=ivy.array([[4.], [5.], [6.]]), b=ivy.array([[5.], [6.], [7.]])) >>> z = ivy.greater_equal(x, y) >>> print(z) {a:ivy.array([[True,False,False],[True,False,False],[False,False,False]]),b:ivy.array([[True,False,False],[False,False,False],[False,False,False]])}
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([4, 5, 6]), b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([1, 2, 3]), b=ivy.array([5, 6, 7])) >>> z = ivy.greater_equal(x, y) >>> print(z) {a:ivy.array([True,True,True]),b:ivy.array([False,False,False])}
Instance Method Examples
Using
ivy.Array
instance method:>>> x = ivy.array([1, 2, 3]) >>> y = ivy.array([4, 5, 6]) >>> z = z = x.greater_equal(y) >>> print(z) ivy.array([False,False,False])
Using
ivy.Container
instance method:>>> x = ivy.Container(a=ivy.array([4, 5, 6]), b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([1, 2, 3]), b=ivy.array([5, 6, 7])) >>> z = x.greater_equal(y) >>> print(z) {a:ivy.array([True,True,True]),b:ivy.array([False,False,False])}
Operator Examples
With
ivy.Array
instances:>>> x = ivy.array([6, 2, 3]) >>> y = ivy.array([4, 5, 6]) >>> z = x >= y >>> print(z) ivy.array([True,False,False])
With
ivy.Container
instances:>>> x = ivy.Container(a=ivy.array([4, 5, 6]), b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([1, 2, 3]), b=ivy.array([5, 6, 7])) >>> z = x >= y >>> print(z) {a:ivy.array([True,True,True]),b:ivy.array([False,False,False])}
With mix of
ivy.Array
andivy.Container
instances:>>> x = ivy.array([[5.1, 2.3, -3.6]]) >>> y = ivy.Container(a=ivy.array([[4.], [5.], [6.]]), b=ivy.array([[5.], [6.], [7.]])) >>> z = x >= y >>> print(z) {a:ivy.array([[True,False,False],[True,False,False],[False,False,False]]),b:ivy.array([[True,False,False],[False,False,False],[False,False,False]])}
- ivy.isfinite(x, /, *, out=None)[source]
Tests each element
x_i
of the input arrayx
to determine if finite (i.e., notNaN
and not equal to positive or negative infinity).- Parameters
- Return type
- Returns
ret – an array containing test results. An element
out_i
isTrue
ifx_i
is finite andFalse
otherwise. The returned array must have a data type ofbool
.This method conforms to the
`Array API Standard<https (//data-apis.org/array-api/latest/>`_.)
This docstring is an extension of the `docstring
<https (//data-apis.org/array-api/latest/API_specification/generated/signatures.elementwise_functions.isfinite.html>`)
_ 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.
Functional Examples
With
ivy.Array
input:>>> x = ivy.array([0, ivy.nan, -ivy.inf, float('inf')]) >>> y = ivy.isfinite(x) >>> print(y) ivy.array([ True, False, False, False])
>>> x = ivy.array([0, ivy.nan, -ivy.inf]) >>> y = ivy.zeros(3) >>> ivy.isfinite(x, out=y) >>> print(y) ivy.array([ True, False, False])
>>> x = ivy.array([[9, float('-0')], [ivy.nan, ivy.inf]]) >>> ivy.isfinite(x, out=x) >>> print(x) ivy.array([[ True, True], [False, False]])
With
ivy.NativeArray
input:>>> x = ivy.native_array([0, -0, ivy.nan , -1, ivy.inf]) >>> y = ivy.isfinite(x) >>> print(y) ivy.array([ True, True, False, True, False])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([0., 999999999999]), b=ivy.array([float('-0'), ivy.nan])) >>> y = ivy.isfinite(x) >>> print(y) { a: ivy.array([True, True]), b: ivy.array([True, False]) }
With
ivy.Array
instance method:>>> x = ivy.array([[9, float('-0')], [ivy.nan, ivy.inf]]) >>> y = x.isfinite() >>> print(y) ivy.array([[ True, True], [False, False]])
With
ivy.Container
instance method:>>> x = ivy.Container(a=ivy.array([0., 999999999999]), b=ivy.array([float('-0'), ivy.nan])) >>> y = x.isfinite() >>> print(y) { a: ivy.array([True, True]), b: ivy.array([True, False]) }
- ivy.isinf(x, /, *, out=None)[source]
Tests each element x_i of the input array x to determine if equal to positive or negative infinity.
- Parameters
- Return type
- Returns
ret – an array containing test results. An element out_i is True if x_i is either positive or negative infinity and False otherwise. The returned array must have a data type of bool.
This function conforms to the `Array API Standard
<https (//data-apis.org/array-api/latest/>`_. This docstring is an extension of the)
`docstring <https (//data-apis.org/array-api/latest/API_specification/generated/signatures.elementwise_functions.isinf.html>`_ )
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: >>> x = ivy.array([1, 2, 3]) >>> z = ivy.isinf(x) >>> print(z) ivy.array([False, False, False])>>> x = ivy.array([[1.1, 2.3, -3.6]]) >>> z = ivy.isinf(x) >>> print(z) ivy.array([[False, False, False]])
>>> x = ivy.array([[[1.1], [float('inf')], [-6.3]]]) >>> z = ivy.isinf(x) >>> print(z) ivy.array([[[False], [True], [False]]])
>>> x = ivy.array([[-math.inf, np.inf, 0.0]]) >>> z = ivy.isinf(x) >>> print(z) ivy.array([[ True, True, False]])
>>> x = ivy.zeros((3, 3)) >>> z = ivy.isinf(x) >>> print(z) ivy.array([[False, False, False], [False, False, False], [False, False, False]])
With
ivy.NativeArray
inputs:>>> x = ivy.native_array([[1], [5], [-ivy.inf]]) >>> z = ivy.isinf(x) >>> print(z) ivy.array([[False], [False], [True]])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([-1, -np.inf, 1.23]), b=ivy.array([math.inf, 3.3, -4.2])) >>> z = ivy.isinf(x) >>> print(z) { a: ivy.array([False, True, False]), b: ivy.array([True, False, False]) }
Instance Method Examples
With
ivy.Array
inputs: >>> x = ivy.array([1, 2, 3]) >>> x.isinf() ivy.array([False, False, False])>>> x = ivy.array([[1.1, 2.3, -3.6]]) >>> x.isinf() ivy.array([[False, False, False]])
>>> x = ivy.array([[[1.1], [float('inf')], [-6.3]]]) >>> x.isinf() ivy.array([[[False], [True], [False]]])
>>> x = ivy.array([[-math.inf, np.inf, 0.0]]) >>> x.isinf() ivy.array([[ True, True, False]])
>>> x = ivy.zeros((3, 3)) >>> x.isinf() ivy.array([[False, False, False], [False, False, False], [False, False, False]])
With
ivy.NativeArray
inputs:>>> x = ivy.native_array([[1], [5], [-ivy.inf]]) >>> x.isinf() ivy.array([[False], [False], [True]])
With
ivy.Container
input: >>> x = ivy.Container(a=ivy.array([-1, -np.inf, 1.23]), b=ivy.array([math.inf, 3.3, -4.2])) >>> x.isinf() {a: ivy.array([False, True, False]), b: ivy.array([True, False, False])
}
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([-1, -np.inf, 1.23]), b=ivy.array([math.inf, 3.3, -4.2])) >>> z = ivy.Container.static_isinf(x) >>> print(z) { a: ivy.array([False, True, False]), b: ivy.array([True, False, False]) }
- ivy.isnan(x, /, *, out=None)[source]
Tests each element
x_i
of the input arrayx
to determine whether the element isNaN
.- Parameters
- Return type
- Returns
ret – an array containing test results. An element
out_i
isTrue
ifx_i
isNaN
andFalse
otherwise. The returned array should have a data type ofbool
.This function conforms to the `Array API Standard
<https (//data-apis.org/array-api/latest/>`_. This docstring is an extension of the)
`docstring <https (//data-apis.org/array-api/latest/API_specification/generated/signatures.elementwise_functions.isnan.html>`_ )
in the standard. The descriptions above assume an array input for simplicity, but
the method also accepts
ivy.Container
instances in place ofivy.Array
orivy.NativeArray
instances, as shown in the type hintsand also the examples below.
Examples
With
ivy.Array
inputs: >>> x = ivy.array([1, 2, 3]) >>> z = ivy.isnan(x) >>> print(z) ivy.array([False, False, False])>>> x = ivy.array([[1.1, 2.3, -3.6]]) >>> z = ivy.isnan(x) >>> print(z) ivy.array([[False, False, False]])
>>> x = ivy.array([[[1.1], [float('inf')], [-6.3]]]) >>> z = ivy.isnan(x) >>> print(z) ivy.array([[[False], [False], [False]]])
>>> x = ivy.array([[-math.nan, np.nan, 0.0]]) >>> z = ivy.isnan(x) >>> print(z) ivy.array([[ True, True, False]])
>>> x = ivy.array([[-math.nan, np.inf, np.nan, 0.0]]) >>> z = ivy.isnan(x) >>> print(z) ivy.array([[ True, False, True, False]])
>>> x = ivy.zeros((3, 3)) >>> z = ivy.isnan(x) >>> print(z) ivy.array([[False, False, False], [False, False, False], [False, False, False]])
With
ivy.NativeArray
inputs:>>> x = ivy.native_array([[1], [5], [-ivy.nan]]) >>> z = ivy.isnan(x) >>> print(z) ivy.array([[False], [False], [True]])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([-1, -np.nan, 1.23]), b=ivy.array([math.nan, 3.3, -4.2])) >>> z = ivy.isnan(x) >>> print(z) { a: ivy.array([False, True, False]), b: ivy.array([True, False, False]) }
Instance Method Examples
With
ivy.Array
inputs: >>> x = ivy.array([1, 2, 3]) >>> x.isnan() ivy.array([False, False, False])>>> x = ivy.array([[1.1, 2.3, -3.6]]) >>> x.isnan() ivy.array([[False, False, False]])
>>> x = ivy.array([[[1.1], [float('inf')], [-6.3]]]) >>> x.isnan() ivy.array([[[False], [False], [False]]])
>>> x = ivy.array([[-math.nan, np.nan, 0.0]]) >>> x.isnan() ivy.array([[ True, True, False]])
>>> x = ivy.array([[-math.nan, np.inf, np.nan, 0.0]]) >>> x.isnan() ivy.array([[ True, False, True, False]])
>>> x = ivy.zeros((3, 3)) >>> x.isnan() ivy.array([[False, False, False], [False, False, False], [False, False, False]])
With
ivy.NativeArray
inputs:>>> x = ivy.native_array([[1], [5], [-ivy.nan]]) >>> x.isnan() ivy.array([[False], [False], [True]])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([-1, -np.nan, 1.23]), b=ivy.array([math.nan, 3.3, -4.2])) >>> x.isnan() { a: ivy.array([False, True, False]), b: ivy.array([True, False, False]) }
With
ivy.Container
input: >>> x = ivy.Container(a=ivy.array([-1, -np.nan, 1.23]), b=ivy.array([math.nan, 3.3, -4.2])) >>> z = ivy.Container.static_isnan(x) >>> print(z) {a: ivy.array([False, True, False]), b: ivy.array([True, False, False])
}
- ivy.less(x1, x2, /, *, out=None)[source]
Computes the truth value of
x1_i < x2_i
for each elementx1_i
of the input arrayx1
with the respective elementx2_i
of the input arrayx2
.- Parameters
x1 (
Union
[float
,Array
,NativeArray
]) – first input array. Should have a numeric data type.x2 (
Union
[float
,Array
,NativeArray
]) – second input array. Must be compatible withx1
(see ref:broadcasting). Should have a numeric data type.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
- Returns
ret – an array containing the element-wise results. The returned array must have a data type of
bool
.
Examples
With
ivy.Array
input:>>> x = ivy.less(ivy.array([1,2,3]),ivy.array([2,2,2])) >>> print(x) ivy.array([ True, False, False])
>>> x = ivy.array([[[1.1], [3.2], [-6.3]]]) >>> y = ivy.array([[8.4], [2.5], [1.6]]) >>> ivy.less(x, y, out=x) >>> print(x) ivy.array([[[1.],[0.],[1.]]])
With
ivy.NativeArray
input:>>> x = ivy.native_array([1, 2]) >>> y = ivy.native_array([4, 5]) >>> z = ivy.less(x, y) >>> print(z) ivy.array([ True, True])
With a mix of
ivy.Array
andivy.NativeArray
inputs:>>> x = ivy.array([1, 2, 3]) >>> y = ivy.native_array([4, 5, 0]) >>> z = ivy.less(x, y) >>> print(z) ivy.array([ True, True, False])
With a mix of
ivy.Array
andivy.Container
inputs:>>> x = ivy.array([[5.1, 2.3, -3.6]]) >>> y = ivy.Container(a=ivy.array([[4.], [5.], [6.]]), b=ivy.array([[5.], [6.], [7.]])) >>> z = ivy.less(x, y) >>> print(z) { a: ivy.array([[False, True, True], [False, True, True], [True, True, True]]), b: ivy.array([[False, True, True], [True, True, True], [True, True, True]]) }
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([4, 5, 6]), b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([1, 2, 3]), b=ivy.array([5, 6, 7])) >>> z = ivy.less(x, y) >>> print(z) { a: ivy.array([False, False, False]), b: ivy.array([True, True, True]) }
- ivy.less_equal(x1, x2, /, *, out=None)[source]
Computes 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
- Return type
- Returns
ret – an array containing the element-wise 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.
Examples
With
ivy.Array
input:>>> x = ivy.less_equal(ivy.array([1,2,3]),ivy.array([2,2,2])) >>> print(x) ivy.array([True, True, False])
>>> x = ivy.array([[10.1, 2.3, -3.6]]) >>> y = ivy.array([[4.8], [5.2], [6.1]]) >>> shape = (3,3) >>> fill_value = False >>> z = ivy.full(shape, fill_value) >>> ivy.less_equal(x, y, out=z) >>> print(z) ivy.array([[False, True, True], [ False, True, True], [ False, True, True]])
>>> x = ivy.array([[[1.1], [3.2], [-6.3]]]) >>> y = ivy.array([[8.4], [2.5], [1.6]]) >>> ivy.less_equal(x, y, out=x) >>> print(x) ivy.array([[[1.],[0.],[1.]]])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([4, 5, 6]), b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([1, 2, 3]), b=ivy.array([5, 6, 7])) >>> z = ivy.less_equal(x, y) >>> print(z) { a: ivy.array([False, False, False]), b: ivy.array([True, True, True]) }
- ivy.log(x, /, *, out=None)[source]
Calculates an implementation-dependent approximation to the natural (base
e
) logarithm, having domain[0, +infinity]
and codomain[-infinity, +infinity]
, for each elementx_i
of the input arrayx
.Special cases
For floating-point operands,
If
x_i
isNaN
, the result isNaN
.If
x_i
is less than0
, the result isNaN
.If
x_i
is either+0
or-0
, the result is-infinity
.If
x_i
is1
, the result is+0
.If
x_i
is+infinity
, the result is+infinity
.
- Parameters
- Return type
- Returns
ret – an array containing the evaluated natural logarithm for each element in
x
. The returned array must have a floating-point data type determined by type-promotion.
- ivy.log10(x, /, *, out=None)[source]
Calculates an implementation-dependent approximation to the base
10
logarithm, having domain[0, +infinity]
and codomain[-infinity, +infinity]
, for each elementx_i
of the input arrayx
.Special cases
For floating-point operands,
If
x_i
isNaN
, the result isNaN
.If
x_i
is less than0
, the result isNaN
.If
x_i
is either+0
or-0
, the result is-infinity
.If
x_i
is1
, the result is+0
.If
x_i
is+infinity
, the result is+infinity
.
- Parameters
- Return type
- Returns
ret – an array containing the evaluated base
10
logarithm for each element inx
. The returned array must have a floating-point data type determined by type-promotion.This function conforms to the `Array API Standard
<https (//data-apis.org/array-api/latest/>`_. This docstring is an extension of the)
`docstring <https (//data-apis.org/array-api/latest/API_specification/generated/signatures.elementwise_functions.ceil.html>`_ )
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
input:>>> x = ivy.array([4.0, 1, -0.0, -5.0]) >>> y = ivy.log10(x) >>> print(y) ivy.array([0.602, 0., -inf, nan])
>>> x = ivy.array([[float('nan'), 1, 5.0, float('+inf')], [+0, -1.0, -5, float('-inf')]]) >>> y = ivy.log10(x) >>> print(y) ivy.array([[nan, 0., 0.699, inf], [-inf, nan, nan, nan]])
With
ivy.NativeArray
input:>>> x = ivy.native_array([5.78, float('-inf')]) >>> y = ivy.log10(x) >>> print(y) ivy.array([0.762, nan])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([0.0, float('nan')]), b=ivy.array([-0., -3.9, float('+inf')]), c=ivy.array([7.9, 1.1, 1.])) >>> y = ivy.log10(x) >>> print(y) { a: ivy.array([-inf, nan]), b: ivy.array([-inf, nan, inf]), c: ivy.array([0.898, 0.0414, 0.]) }
- ivy.log1p(x, /, *, out=None)[source]
Calculates an implementation-dependent approximation to log(1+x), where log refers to the natural (base e) logarithm. .. note:
The purpose of this function is to calculate ``log(1+x)`` more accurately when `x` is close to zero. Accordingly, conforming implementations should avoid implementing this function as simply ``log(1+x)``. See FDLIBM, or some other IEEE 754-2019 compliant mathematical library, for a potential reference implementation.
Special cases
For floating-point operands,
If
x_i
isNaN
, the result isNaN
.If
x_i
is less than-1
, the result isNaN
.If
x_i
is-1
, the result is-infinity
.If
x_i
is-0
, the result is-0
.If
x_i
is+0
, the result is+0
.If
x_i
is+infinity
, the result is+infinity
.
- Parameters
- Return type
- Returns
ret – an array containing the evaluated Natural logarithm of 1 + x for each element in
x
. The returned array must have a floating-point data type determined by type-promotion.This function conforms to the `Array API Standard
<https (//data-apis.org/array-api/latest/>`_. This docstring is an extension of the)
`docstring <https (//data-apis.org/array-api/latest/API_specification/generated/signatures.elementwise_functions.add.html>`_ )
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
input:>>> x = ivy.array([1 , 2 ,3 ]) >>> y = ivy.log1p(x) >>> print(y) ivy.array([0.693, 1.1 , 1.39 ])
>>> x = ivy.array([0 , 1 ]) >>> y = ivy.zeros(2) >>> ivy.log1p(x , out = y) >>> print(y) ivy.array([0. , 0.693])
>>> x = ivy.array([[1.1, 2.2, 3.3], [4.4, 5.5, 6.6]]) >>> ivy.log1p(x , out = x) >>> print(x) ivy.array([[0.742, 1.16 , 1.46 ], [1.69 , 1.87 , 2.03 ]])
>>> x = ivy.array([1e-9] , dtype = ivy.float32) >>> y = x.log1p() >>> print(y) ivy.array([1.e-09])
With
ivy.NativeArray
input:>>> x = ivy.native_array([10., 20.]) >>> y = ivy.log1p(x) >>> print(y) ivy.array([2.4 , 3.04])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.1])) >>> y = ivy.Container.static_log1p(x) >>> print(y) { a: ivy.array([0., 0.693, 1.1]), b: ivy.array([1.39, 1.61, 1.81]) }
- ivy.log2(x, /, *, out=None)[source]
Calculates an implementation-dependent approximation to the base
2
logarithm, having domain[0, +infinity]
and codomain[-infinity, +infinity]
, for each elementx_i
of the input arrayx
.Special cases
For floating-point operands,
If
x_i
isNaN
, the result isNaN
.If
x_i
is less than0
, the result isNaN
.If
x_i
is either+0
or-0
, the result is-infinity
.If
x_i
is1
, the result is+0
.If
x_i
is+infinity
, the result is+infinity
.
- Parameters
- Return type
- Returns
ret – an array containing the evaluated base
2
logarithm for each element inx
. The returned array must have a floating-point data type determined by type-promotion.
- ivy.logaddexp(x1, x2, /, *, out=None)[source]
Calculates the logarithm of the sum of exponentiations
log(exp(x1) + exp(x2))
for each elementx1_i
of the input arrayx1
with the respective elementx2_i
of the input arrayx2
.Special cases
For floating-point operands,
If either
x1_i
orx2_i
isNaN
, the result isNaN
.If
x1_i
is+infinity
andx2_i
is notNaN
, the result is+infinity
.If
x1_i
is notNaN
andx2_i
is+infinity
, the result is+infinity
.
- Parameters
x1 (
Union
[Array
,NativeArray
]) – first input array. Should have a floating-point data type.x2 (
Union
[Array
,NativeArray
]) – second input array. Must be compatible withx1
(see broadcasting). Should have a floating-point data type.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
- Returns
ret – an array containing the element-wise results. The returned array must have a floating-point data type determined by type-promotion.
- ivy.logical_and(x1, x2, /, *, out=None)[source]
Computes the logical AND for each element x1_i of the input array x1 with the respective element x2_i of the input array x2.
- Parameters
x1 (
Union
[Array
,NativeArray
]) – first input array. Should have a boolean data type.x2 (
Union
[Array
,NativeArray
]) – second input array. Must be compatible with x1. Should have a boolean data type.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
- Returns
ret – an array containing the element-wise results. The returned array must have a data type of bool.
Examples
>>> x = ivy.array([True, True, False]) >>> y = ivy.array([True, False, True]) >>> print(ivy.logical_and(x, y)) ivy.array([True,False,False])
>>> ivy.logical_and(x, y, out=y) >>> print(y) ivy.array([True,False,False])
>>> x = ivy.Container(a=ivy.array([False, True, True]), b=ivy.array([True, False, False])) >>> y = ivy.Container(a=ivy.array([True, True, False]), b=ivy.array([False, False, True])) >>> print(ivy.logical_and(y, x)) {a:ivy.array([False,True,False]),b:ivy.array([False,False,False])}
>>> ivy.logical_and(y, x, out=y) >>> print(y) {a:ivy.array([False,True,False]),b:ivy.array([False,False,False])}
>>> x = ivy.native_array([True, True, False]) >>> y = ivy.native_array([True, False, True]) >>> print(ivy.logical_and(x, y)) ivy.array([True,False,False])
>>> ivy.logical_and(x, y, out=y) >>> print(y) tensor([True,False,False])
>>> x = ivy.Container(a=ivy.array([False, True, True]), b=ivy.array([True, False, False])) >>> y = ivy.array([True, False, True]) >>> print(ivy.logical_and(y, x)) {a:ivy.array([False,False,True]),b:ivy.array([True,False,False])}
>>> x = ivy.Container(a=ivy.array([False, True, True]), b=ivy.array([True, False, False])) >>> y = ivy.array([True, False, True]) >>> ivy.logical_and(y, x, out=x) >>> print(x) { a: ivy.array([False, False, True]), b: ivy.array([True, False, False]) }
- ivy.logical_not(x, /, *, out=None)[source]
Computes the logical NOT for each element
x_i
of the input arrayx
.Note
While this specification recommends that this function only accept input arrays having a boolean data type, specification-compliant array libraries may choose to accept input arrays having numeric data types. If non-boolean data types are supported, zeros must be considered the equivalent of
False
, while non-zeros must be considered the equivalent ofTrue
.Special cases
For this particular case,
If
x_i
isNaN
, the result isFalse
.If
x_i
is-0
, the result isTrue
.If
x_i
is-infinity
, the result isFalse
.If
x_i
is+infinity
, the result isFalse
.
- Parameters
- Return type
- Returns
ret – an array containing the element-wise results. The returned array must have a data type of
bool
.
Functional Examples
With
ivy.Array
input:>>> x=ivy.array([1,0,1,1,0]) >>> y=ivy.logical_not(x) >>> print(y) ivy.array([False, True, False, False, True])
>>> x=ivy.array([2,0,3,5]) >>> y=ivy.logical_not(x) >>> print(y) ivy.array([False, True, False, False])
With
ivy.NativeArray
input:>>> x=ivy.native_array([1,0,1,1,0]) >>> y=ivy.logical_not(x) >>> print(y) ivy.array([False, True, False, False, True])
>>> x=ivy.native_array([1,0,6,5]) >>> y=ivy.logical_not(x) >>> print(y) ivy.array([False, True, False, False])
With
ivy.Container
input:>>> x=ivy.Container(a=ivy.array([1,0,1,1]), b=ivy.array([1,0,8,9])) >>> y=ivy.logical_not(x) >>> print(y) { a: ivy.array([False, True, False, False]), b: ivy.array([False, True, False, False]) }
>>> x=ivy.Container(a=ivy.array([1,0,1,0]), b=ivy.native_array([5,2,0,3])) >>> y=ivy.logical_not(x) >>> print(y) { a: ivy.array([False, True, False, True]), b: ivy.array([False, False, True, False]) }
Instance Method Examples
With
ivy.Array
input:>>> x=ivy.array([0,1,1,0]) >>> x.logical_not() ivy.array([ True, False, False, True])
>>> x=ivy.array([2,0,3,9]) >>> x.logical_not() ivy.array([False, True, False, False])
With
ivy.Container
input:>>> x=ivy.Container(a=ivy.array([1,0,0,1]), b=ivy.array([3,1,7,0])) >>> x.logical_not() { a: ivy.array([False, True, True, False]), b: ivy.array([False, False, False, True]) }
>>> x=ivy.Container(a=ivy.array([1,0,1,0]), b=ivy.native_array([5,2,0,3])) >>> x.logical_not() { a: ivy.array([False, True, False, True]), b: ivy.array([False, False, True, False]) }
- ivy.logical_or(x1, x2, /, *, out=None)[source]
Computes the logical OR for each element
x1_i
of the input arrayx1
with the respective elementx2_i
of the input arrayx2
.Note
While this specification recommends that this function only accept input arrays having a boolean data type, specification-compliant array libraries may choose to accept input arrays having numeric data types. If non-boolean data types are supported, zeros must be considered the equivalent of
False
, while non-zeros must be considered the equivalent ofTrue
.- Parameters
x1 (
Union
[Array
,NativeArray
]) – first input array. Should have a boolean data type.x2 (
Union
[Array
,NativeArray
]) – second input array. Must be compatible withx1
(see broadcasting). Should have a boolean data type.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
- Returns
ret – an array containing the element-wise results. The returned array must have a data type of
bool
.
- ivy.logical_xor(x1, x2, /, *, out=None)[source]
Computes the bitwise XOR of the underlying binary representation of each element
x1_i
of the input arrayx1
with the respective elementx2_i
of the input arrayx2
.- Parameters
x1 (
Union
[Array
,NativeArray
]) – first input array. Should have an integer or boolean data type.x2 (
Union
[Array
,NativeArray
]) – second input array. Must be compatible withx1
(see broadcasting). Should have an integer or boolean data type.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
- Returns
ret – an array containing the element-wise results. The returned array must have a data type determined by type-promotion.
Examples
With
ivy.Array
inputs:>>> x = ivy.array([1,0,1,1,0]) >>> y = ivy.array([1,0,1,1,0]) >>> z = ivy.logical_xor(x,y) >>> print(z) ivy.array([False, False, False, False, False])
>>> x = ivy.array([[[1], [2], [3], [4]]]) >>> y = ivy.array([[[4], [5], [6], [7]]]) >>> z = ivy.logical_xor(x,y) >>> print(z) ivy.array([[[False], [False], [False], [False]]])
>>> x = ivy.array([[[1], [2], [3], [4]]]) >>> y = ivy.array([4, 5, 6, 7]) >>> z = ivy.logical_xor(x,y) >>> print(z) ivy.array([[[False, False, False, False], [False, False, False, False], [False, False, False, False], [False, False, False, False]]])
With
ivy.Container
inputs:>>> x = ivy.Container(a=ivy.array([1,0,0,1,0]), b=ivy.array([1,0,1,0,0])) >>> y = ivy.Container(a=ivy.array([0,0,1,1,0]), b=ivy.array([1,0,1,1,0])) >>> z = ivy.logical_xor(x,y) >>> print(z) { a: ivy.array([True, False, True, False, False]), b: ivy.array([False, False, False, True, False]) }
With a mix of
ivy.Array
andivy.Container
inputs:>>> x = ivy.Container(a=ivy.array([1,0,0,1,0]), b=ivy.array([1,0,1,0,0])) >>> y = ivy.array([0,0,1,1,0]) >>> z = ivy.logical_xor(x,y) >>> print(z) { a: ivy.array([True, False, True, False, False]), b: ivy.array([True, False, False, True, False]) }
- ivy.maximum(x1, x2, /, *, out=None)[source]
Returns the max of x1 and x2 (i.e. x1 > x2 ? x1 : x2) element-wise.
- Parameters
x1 (
Union
[Array
,NativeArray
,Number
]) – Input array containing elements to maximum threshold.x2 (
Union
[Array
,NativeArray
,Number
]) – Tensor containing maximum values, must be broadcastable to x1.out (
Optional
[Union
[Array
,NativeArray
]]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
Union
[Array
,NativeArray
]- Returns
ret – An array with the elements of x1, but clipped to not be lower than the x2 values.
This function conforms to the `Array API Standard
<https (//data-apis.org/array-api/latest/>`_. This docstring is an extension of the)
`docstring <https (//data-apis.org/array-api/latest/API_specification/generated/signatures.elementwise_functions.add.html>`_ )
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: >>> x = ivy.array([7, 9, 5]) >>> y = ivy.array([9, 3, 2]) >>> z = ivy.maximum(x, y) >>> print(z) ivy.array([9, 9, 5])>>> x = ivy.array([1, 5, 9, 8, 3, 7]) >>> y = ivy.array([[9], [3], [2]]) >>> z = ivy.zeros((3, 6)) >>> ivy.maximum(x, y, out=z) >>> print(z) ivy.array([[9.,9.,9.,9.,9.,9.], [3.,5.,9.,8.,3.,7.], [2.,5.,9.,8.,3.,7.]])
>>> x = ivy.array([[7, 3]]) >>> y = ivy.array([0, 7]) >>> ivy.maximum(x, y, out=x) >>> print(x) ivy.array([[7, 7]])
With one
ivy.Container
input:>>> x = ivy.array([[1, 3], [2, 4], [3, 7]]) >>> y = ivy.Container(a=ivy.array([1, 0,]), b=ivy.array([-5, 9])) >>> z = ivy.maximum(x, y) >>> print(z) { a: ivy.array([[1, 3], [2, 4], [3, 7]]), b: ivy.array([[1, 9], [2, 9], [3, 9]]) }
With multiple
ivy.Container
inputs:>>> x = ivy.Container(a=ivy.array([1, 3, 1]), b=ivy.array([2, 8, 5])) >>> y = ivy.Container(a=ivy.array([1, 5, 6]), b=ivy.array([5, 9, 7])) >>> z = ivy.maximum(x, y) >>> print(z) { a: ivy.array([1, 5, 6]), b: ivy.array([5, 9, 7]) }
- ivy.minimum(x1, x2, /, *, out=None)[source]
Returns the min of x1 and x2 (i.e. x1 < x2 ? x1 : x2) element-wise.
- Parameters
x1 (
Union
[Array
,NativeArray
]) – Input array containing elements to minimum threshold.x2 (
Union
[Array
,NativeArray
]) – Tensor containing minimum values, must be broadcastable to x1.out (
Optional
[Union
[Array
,NativeArray
]]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
Union
[Array
,NativeArray
]- Returns
ret – An array with the elements of x1, but clipped to not exceed the x2 values.
This function conforms to the `Array API Standard
<https (//data-apis.org/array-api/latest/>`_. This docstring is an extension of the)
`docstring <https (//data-apis.org/array-api/latest/API_specification/generated/signatures.elementwise_functions.add.html>`_ )
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: >>> x = ivy.array([7, 9, 5]) >>> y = ivy.array([9, 3, 2]) >>> z = ivy.minimum(x, y) >>> print(z) ivy.array([7, 3, 2])>>> x = ivy.array([1, 5, 9, 8, 3, 7]) >>> y = ivy.array([[9], [3], [2]]) >>> z = ivy.zeros((3, 6)) >>> ivy.minimum(x, y, out=z) >>> print(z) ivy.array([[1.,5.,9.,8.,3.,7.], [1.,3.,3.,3.,3.,3.], [1.,2.,2.,2.,2.,2.]])
>>> x = ivy.array([[7, 3]]) >>> y = ivy.array([0, 7]) >>> ivy.minimum(x, y, out=x) >>> print(x) ivy.array([[0, 3]])
With one
ivy.Container
input:>>> x = ivy.array([[1, 3], [2, 4], [3, 7]]) >>> y = ivy.Container(a=ivy.array([1, 0,]), b=ivy.array([-5, 9])) >>> z = ivy.minimum(x, y) >>> print(z) { a: ivy.array([[1, 0], [1, 0], [1, 0]]), b: ivy.array([[-5, 3], [-5, 4], [-5, 7]]) }
With multiple
ivy.Container
inputs:>>> x = ivy.Container(a=ivy.array([1, 3, 1]), b=ivy.array([2, 8, 5])) >>> y = ivy.Container(a=ivy.array([1, 5, 6]), b=ivy.array([5, 9, 7])) >>> z = ivy.minimum(x, y) >>> print(z) { a: ivy.array([1, 3, 1]), b: ivy.array([2, 8, 5]) }
- ivy.multiply(x1, x2, /, *, out=None)[source]
Calculates the product for each element
x1_i
of the input arrayx1
with the respective elementx2_i
of the input arrayx2
.Special cases
For floating-point operands,
If either
x1_i
orx2_i
isNaN
, the result isNaN
.If
x1_i
is either+infinity
or-infinity
andx2_i
is either+0
or-0
, the result isNaN
.If
x1_i
is either+0
or-0
andx2_i
is either+infinity
or-infinity
, the result isNaN
.If
x1_i
andx2_i
have the same mathematical sign, the result has a positive mathematical sign, unless the result isNaN
. If the result isNaN
, the “sign” ofNaN
is implementation-defined.If
x1_i
andx2_i
have different mathematical signs, the result has a negative mathematical sign, unless the result isNaN
. If the result isNaN
, the “sign” ofNaN
is implementation-defined.If
x1_i
is either+infinity
or-infinity
andx2_i
is either+infinity
or-infinity
, the result is a signed infinity with the mathematical sign determined by the rule already stated above.If
x1_i
is either+infinity
or-infinity
andx2_i
is a nonzero finite number, the result is a signed infinity with the mathematical sign determined by the rule already stated above.If
x1_i
is a nonzero finite number andx2_i
is either+infinity
or-infinity
, the result is a signed infinity with the mathematical sign determined by the rule already stated above.
In the remaining cases, where neither
infinity
norNaN
is involved, the product must be computed and rounded to the nearest representable value according to IEEE 754-2019 and a supported rounding mode. If the magnitude is too large to represent, the result is aninfinity
of appropriate mathematical sign. If the magnitude is too small to represent, the result is a zero of appropriate mathematical sign.Note
Floating-point multiplication is not always associative due to finite precision.
- Parameters
x1 (
Union
[Array
,NativeArray
]) – first input array. Should have a numeric data type.x2 (
Union
[Array
,NativeArray
]) – second input array. Must be compatible withx1
(see ref:Broadcasting). Should have a numeric data type.out (
Optional
[Union
[Array
,NativeArray
]]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
- Returns
ret – an array containing the element-wise products. The returned array must have a data type determined by Type Promotion Rules.
- ivy.negative(x, /, *, out=None)[source]
Computes the numerical negative of each element x_i (i.e., y_i = -x_i) of the input array x.
- Parameters
- Return type
- Returns
ret – an array containing the evaluated result for each element in x
Functional Examples
With
ivy.Array
input:>>> x = ivy.array([0,1,1,2]) >>> y = ivy.negative(x) >>> print(y) ivy.array([0,-1,-1,-2])
>>> x = ivy.array([0,-1,-0.5,2,3]) >>> y = ivy.zeros(5) >>> ivy.negative(x,out=y) >>> print(y) ivy.array([-0.,1.,0.5,-2.,-3.])
>>> x = ivy.array([[1.1,2.2,3.3], [-4.4,-5.5,-6.6]]) >>> ivy.negative(x,out=x) >>> print(x) ivy.array([[-1.1,-2.2,-3.3],[4.4,5.5,6.6]])
With
ivy.NativeArray
input:>>> x = ivy.native_array([-1.1,-1,0,1,1.1]) >>> y = ivy.negative(x) >>> print(y) ivy.array([1.1,1.,-0.,-1.,-1.1])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([0.,1.,2.]), b=ivy.array([3.,4.,-5.])) >>> y = ivy.negative(x) >>> print(y) {a:ivy.array([-0.,-1.,-2.]),b:ivy.array([-3.,-4.,5.])}
Instance Method Examples
Using
ivy.Array
instance method:>>> x = ivy.array([-1.1,-1,0,-0,1,1.1]) >>> y = x.negative() >>> print(y) ivy.array([1.1,1.,-0.,-0.,-1.,-1.1])
Using
ivy.Container
instance method:>>> x = ivy.Container(a=ivy.array([1,2,3]), b=ivy.array([-4.4,5,-6.6])) >>> y = x.negative() >>> print(y) {a:ivy.array([-1,-2,-3]),b:ivy.array([4.4,-5.,6.6])}
Operator Examples
Using
ivy.Array
instance method:>>> x = ivy.array([1,2,3]) >>> y = -x >>> print(y) ivy.array([-1,-2,-3])
Using
ivy.Container
instance method:>>> x = ivy.Container(a=ivy.array([1,2,3]), b=ivy.array([-4.4,5,-6.6])) >>> y = -x >>> print(y) {a:ivy.array([-1,-2,-3]),b:ivy.array([4.4,-5.,6.6])}
- ivy.not_equal(x1, x2, /, *, out=None)[source]
Computes the truth value of
x1_i != x2_i
for each elementx1_i
of the input arrayx1
with the respective elementx2_i
of the input arrayx2
.- Parameters
x1 (
Union
[float
,Array
,NativeArray
]) – first input array. Should have a numeric data type.x2 (
Union
[float
,Array
,NativeArray
]) – second input array. Must be compatible withx1
(see ref:broadcasting). Should have a numeric data type.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
- 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
<https (//data-apis.org/array-api/latest/>`_. This docstring is an extension of the)
`docstring <https (//data-apis.org/array-api/latest/API_specification/generated/signatures.elementwise_functions.not_equal.html>`_ )
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.
Functional 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
andivy.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
andivy.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]) }
Instance Method Examples
Using
ivy.Array
instance method:>>> x1 = ivy.array([1, 0, 1, 1]) >>> x2 = ivy.array([1, 0, 0, -1]) >>> y = x1.not_equal(x2, out=x2) >>> print(y) ivy.array([0, 0, 1, 1])
>>> x1 = ivy.array([1, 0, 1, 0]) >>> x2 = ivy.array([0, 1, 0, 1]) >>> y = x1.not_equal(x2, out=x2) >>> print(y) ivy.array([1, 1, 1, 1])
Using
ivy.Container
instance method:>>> 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 = x1.not_equal(x2, out=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, 3, 3.0]), b=ivy.array([1.0, 4.0, 5.0])) >>> y = x1.not_equal(x2, out=x2) >>> print(y) { a: ivy.array([False, True, False]), b: ivy.array([False, False, False]) }
Operator Examples
With
ivy.Array
instances:>>> x1 = ivy.array([1, 0, 1, 1]) >>> x2 = ivy.array([1, 0, 0, -1]) >>> y = (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 = (x1 != x2) >>> print(y) ivy.array([True, True, True, True])
With
ivy.Container
instances:>>> 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 = (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, 3, 3.0]), b=ivy.array([1.0, 4.0, 5.0])) >>> y = (x1 != x2) >>> print(y) { a: ivy.array([False, True, False]), b: ivy.array([False, False, False]) }
With a mix of
ivy.Array
andivy.Container
instances:>>> 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 = (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 = (x1 != x2) >>> print(y) { a: ivy.array([False, False, False]), b: ivy.array([False, False, False]) }
- ivy.positive(x, /, *, out=None)[source]
Returns a new array with the positive value of each element in
x
.
- ivy.pow(x1, x2, /, *, out=None)[source]
Calculates an implementation-dependent approximation of exponentiation by raising each element
x1_i
(the base) of the input arrayx1
to the power ofx2_i
(the exponent), wherex2_i
is the corresponding element of the input arrayx2
.Note
If both
x1
andx2
have integer data types, the result ofpow
whenx2_i
is negative (i.e., less than zero) is unspecified and thus implementation-dependent. Ifx1
has an integer data type andx2
has a floating-point data type, behavior is implementation-dependent (type promotion between data type “kinds” (integer versus floating-point) is unspecified).Special cases
For floating-point operands,
If
x1_i
is not equal to1
andx2_i
isNaN
, the result isNaN
.If
x2_i
is+0
, the result is1
, even ifx1_i
isNaN
.If
x2_i
is-0
, the result is1
, even ifx1_i
isNaN
.If
x1_i
isNaN
andx2_i
is not equal to0
, the result isNaN
.If
abs(x1_i)
is greater than1
andx2_i
is+infinity
, the result is+infinity
.If
abs(x1_i)
is greater than1
andx2_i
is-infinity
, the result is+0
.If
abs(x1_i)
is1
andx2_i
is+infinity
, the result is1
.If
abs(x1_i)
is1
andx2_i
is-infinity
, the result is1
.If
x1_i
is1
andx2_i
is notNaN
, the result is1
.If
abs(x1_i)
is less than1
andx2_i
is+infinity
, the result is+0
.If
abs(x1_i)
is less than1
andx2_i
is-infinity
, the result is+infinity
.If
x1_i
is+infinity
andx2_i
is greater than0
, the result is+infinity
.If
x1_i
is+infinity
andx2_i
is less than0
, the result is+0
.If
x1_i
is-infinity
,x2_i
is greater than0
, andx2_i
is an odd integer value, the result is-infinity
.If
x1_i
is-infinity
,x2_i
is greater than0
, andx2_i
is not an odd integer value, the result is+infinity
.If
x1_i
is-infinity
,x2_i
is less than0
, andx2_i
is an odd integer value, the result is-0
.If
x1_i
is-infinity
,x2_i
is less than0
, andx2_i
is not an odd integer value, the result is+0
.If
x1_i
is+0
andx2_i
is greater than0
, the result is+0
.If
x1_i
is+0
andx2_i
is less than0
, the result is+infinity
.If
x1_i
is-0
,x2_i
is greater than0
, andx2_i
is an odd integer value, the result is-0
.If
x1_i
is-0
,x2_i
is greater than0
, andx2_i
is not an odd integer value, the result is+0
.If
x1_i
is-0
,x2_i
is less than0
, andx2_i
is an odd integer value, the result is-infinity
.If
x1_i
is-0
,x2_i
is less than0
, andx2_i
is not an odd integer value, the result is+infinity
.If
x1_i
is less than0
,x1_i
is a finite number,x2_i
is a finite number, andx2_i
is not an integer value, the result isNaN
.
- Parameters
x1 (
Union
[float
,Array
,NativeArray
]) – first input array whose elements correspond to the exponentiation base. Should have a numeric data type.x2 (
Union
[float
,Array
,NativeArray
]) – second input array whose elements correspond to the exponentiation exponent. Must be compatible withx1
(see broadcasting). Should have a numeric data type.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
- Returns
ret – an array containing the element-wise results. The returned array must have a data type determined by type-promotion.
- ivy.remainder(x1, x2, /, *, out=None)[source]
Returns the remainder of division for each element
x1_i
of the input arrayx1
and the respective elementx2_i
of the input arrayx2
.Note
This function is equivalent to the Python modulus operator
x1_i % x2_i
. For input arrays which promote to an integer data type, the result of division by zero is unspecified and thus implementation-defined. In general, similar to Python’s%
operator, this function is not recommended for floating-point operands as semantics do not follow IEEE 754. That this function is specified to accept floating-point operands is primarily for reasons of backward compatibility.Special Cases
For floating-point operands,
If either
x1_i
orx2_i
isNaN
, the result isNaN
.If
x1_i
is either+infinity
or-infinity
andx2_i
is either+infinity
or-infinity
, the result isNaN
.If
x1_i
is either+0
or-0
andx2_i
is either+0
or-0
, the result isNaN
.If
x1_i
is+0
andx2_i
is greater than0
, the result is+0
.If
x1_i
is-0
andx2_i
is greater than0
, the result is+0
.If
x1_i
is+0
andx2_i
is less than0
, the result is-0
.If
x1_i
is-0
andx2_i
is less than0
, the result is-0
.If
x1_i
is greater than0
andx2_i
is+0
, the result isNaN
.If
x1_i
is greater than0
andx2_i
is-0
, the result isNaN
.If
x1_i
is less than0
andx2_i
is+0
, the result isNaN
.If
x1_i
is less than0
andx2_i
is-0
, the result isNaN
.If
x1_i
is+infinity
andx2_i
is a positive (i.e., greater than0
) finite number, the result isNaN
.If
x1_i
is+infinity
andx2_i
is a negative (i.e., less than0
) finite number, the result isNaN
.If
x1_i
is-infinity
andx2_i
is a positive (i.e., greater than0
) finite number, the result isNaN
.If
x1_i
is-infinity
andx2_i
is a negative (i.e., less than0
) finite number, the result isNaN
.If
x1_i
is a positive (i.e., greater than0
) finite number andx2_i
is+infinity
, the result isx1_i
. (note: this result matches Python behavior.)If
x1_i
is a positive (i.e., greater than0
) finite number andx2_i
is-infinity
, the result isx2_i
. (note: this result matches Python behavior.)If
x1_i
is a negative (i.e., less than0
) finite number andx2_i
is+infinity
, the result isx2_i
. (note: this results matches Python behavior.)If
x1_i
is a negative (i.e., less than0
) finite number andx2_i
is-infinity
, the result isx1_i
. (note: this result matches Python behavior.)In the remaining cases, the result must match that of the Python
%
operator.
- Parameters
x1 (
Union
[float
,Array
,NativeArray
]) – dividend input array. Should have a numeric data type.x2 (
Union
[float
,Array
,NativeArray
]) – divisor input array. Must be compatible withx1
(see ref:Broadcasting). Should have a numeric data type.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
- Returns
ret – an array containing the element-wise results. Each element-wise result must have the same sign as the respective element
x2_i
. The returned array must have a data type determined by Type Promotion Rules.
Examples
With
ivy.Array
inputs:>>> x1 = ivy.array([2., 5., 15.]) >>> x2 = ivy.array([3., 2., 4.]) >>> y = ivy.remainder(x1, x2) >>> print(y) ivy.array([2., 1., 3.])
With
ivy.NativeArray
inputs:>>> x1 = ivy.native_array([2., 4., 7.]) >>> x2 = ivy.native_array([3., 2., 5.]) >>> y = ivy.remainder(x1, x2) >>> print(y) ivy.array([2., 0., 2.])
With mixed
ivy.Array
andivy.NativeArray
inputs:>>> x1 = ivy.array([23., 1., 6.]) >>> x2 = ivy.native_array([11., 2., 4.]) >>> y = ivy.remainder(x1, x2) >>> print(y) ivy.array([1., 1., 2.])
With
ivy.Container
inputs:>>> x1 = ivy.Container(a=ivy.array([2., 3., 5.]), b=ivy.array([2., 2., 4.])) >>> x2 = ivy.Container(a=ivy.array([1., 3., 4.]), b=ivy.array([1., 3., 3.])) >>> y = ivy.remainder(x1, x2) >>> print(y) { a: ivy.array([0., 0., 1.]), b: ivy.array([0., 2., 1.]) }
- ivy.round(x, /, *, out=None)[source]
Rounds each element
x_i
of the input arrayx
to the nearest integer-valued number.Special cases
If
x_i
is already an integer-valued, the result isx_i
.
For floating-point operands,
If
x_i
is+infinity
, the result is+infinity
.If
x_i
is-infinity
, the result is-infinity
.If
x_i
is+0
, the result is+0
.If
x_i
is-0
, the result is-0
.If
x_i
isNaN
, the result isNaN
.If two integers are equally close to
x_i
, the result is the even integer closest tox_i
.
- Parameters
- Return type
- Returns
ret – An array of the same shape and type as x, with the elements rounded to integers.
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.Functional Examples
With
ivy.Array
input:>>> x = ivy.array([1.2, 2.4, 3.6]) >>> y = ivy.round(x) >>> print(y) ivy.array([1.,2.,4.])
>>> x = ivy.array([-0, 5, 4.5]) >>> y = ivy.round(x) >>> print(y) ivy.array([0.,5.,4.])
>>> x = ivy.array([1.5654, 2.034, 15.1, -5.0]) >>> y = ivy.zeros(4) >>> ivy.round(x, out=y) >>> print(y) ivy.array([2.,2.,15.,-5.])
>>> x = ivy.array([[0, 5.433, -343.3, 1.5], [-5.5, 44.2, 11.5, 12.01]]) >>> ivy.round(x, out=x) >>> print(x) ivy.array([[0.,5.,-343.,2.],[-6.,44.,12.,12.]])
With
ivy.NativeArray
input:>>> x = ivy.native_array([20.2, 30.5, -5.81]) >>> y = ivy.round(x) >>> print(y) ivy.array([20.,30.,-6.])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([4.20, 8.6, 6.90, 0.0]), b=ivy.array([-300.9, -527.3, 4.5])) >>> y = ivy.round(x) >>> print(y) { a:ivy.array([4.,9.,7.,0.]), b:ivy.array([-301.,-527.,4.]) }
- ivy.sign(x, /, *, out=None)[source]
Returns an indication of the sign of a number for each element
x_i
of the input arrayx
.Special cases
If
x_i
is less than0
, the result is-1
.If
x_i
is either-0
or+0
, the result is0
.If
x_i
is greater than0
, the result is+1
.
- Parameters
- Return type
- Returns
ret – an array containing the evaluated result for each element in
x
. The returned array must have the same data type asx
.
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
input:>>> x = ivy.array([8.3, -0, 6.8, 0.07]) >>> y = ivy.sign(x) >>> print(y) ivy.array([1., 0., 1., 1.])
>>> x = ivy.array([[5.78, -4., -6.9, 0], [-.4, 0.5, 8, -0.01]]) >>> y = ivy.sign(x) >>> print(y) ivy.array([[ 1., -1., -1., 0.], [-1., 1., 1., -1.]])
With
ivy.NativeArray
input:>>> x = ivy.native_array([8.95, -124.6, -0.001, 0, 1.5, 7.1]) >>> y = ivy.sign(x) >>> print(y) ivy.array([ 1., -1., -1., 0., 1., 1.])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([0., -0.]), b=ivy.array([1.46, 5.9, -0.0]), c=ivy.array([-8.23, -4.9, -2.6, 7.4])) >>> y = ivy.sign(x) >>> print(y) { a: ivy.array([0., 0.]), b: ivy.array([1., 1., 0.]), c: ivy.array([-1., -1., -1., 1.]) }
- ivy.sin(x, /, *, out=None)[source]
Calculates an implementation-dependent approximation to the sine, having domain
(-infinity, +infinity)
and codomain[-1, +1]
, for each elementx_i
of the input arrayx
. Each elementx_i
is assumed to be expressed in radians.Special cases
For floating-point operands,
If
x_i
isNaN
, the result isNaN
.If
x_i
is+0
, the result is+0
.If
x_i
is-0
, the result is-0
.If
x_i
is either+infinity
or-infinity
, the result isNaN
.
- Parameters
- Return type
- Returns
ret – an array containing the sine of each element in
x
. The returned array must have a floating-point data type determined by type-promotion.This method conforms to the
`Array API Standard <https (//data-apis.org/array-api/latest/>`_.)
This docstring is an extension of the
`docstring <https (//data-apis.org/array-api/latest/API_specification/generated/)
signatures.elementwise_functions.sin.html>` _ 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
input:>>> x = ivy.array([0., 1., 2.]) >>> y = ivy.sin(x) >>> print(y) ivy.array([0., 0.841, 0.909])
>>> x = ivy.array([0., 1.2, -2.3, 3.6]) >>> y = ivy.zeros(4) >>> ivy.sin(x, out=y) >>> print(y) ivy.array([0., 0.932, -0.746, -0.443])
>>> x = ivy.array([[1., 2., 3.], [-4., -5., -6.]]) >>> ivy.sin(x, out=x) >>> print(x) ivy.array([[0.841, 0.909, 0.141], [0.757, 0.959, 0.279]])
With
ivy.NativeArray
input:>>> x = ivy.native_array([0., 1.2, -2.3, 3.6]) >>> y = ivy.sin(x) >>> print(y) ivy.array([0., 0.932, -0.746, -0.443])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([0., 1., 2., 3.]), b=ivy.array([-4., -5., -6., -7.])) >>> y = ivy.sin(x) >>> print(y) { a: ivy.array([0., 0.841, 0.909, 0.141]), b: ivy.array([0.757, 0.959, 0.279, -0.657]) }
- ivy.sinh(x, /, *, out=None)[source]
Calculates an implementation-dependent approximation to the hyperbolic sine, having domain
[-infinity, +infinity]
and codomain[-infinity, +infinity]
, for each elementx_i
of the input arrayx
.Special cases
For floating-point operands,
If
x_i
isNaN
, the result isNaN
.If
x_i
is+0
, the result is+0
.If
x_i
is-0
, the result is-0
.If
x_i
is+infinity
, the result is+infinity
.If
x_i
is-infinity
, the result is-infinity
.
- Parameters
- Return type
- Returns
ret – an array containing the hyperbolic sine of each element in
x
. The returned array must have a floating-point data type determined by type-promotion.
Examples
With
ivy.Array
input:>>> x = ivy.array([1, 2, 3]) >>> y = ivy.sinh(x) >>> print(y) ivy.array([1.18, 3.63, 10.])
>>> x = ivy.array([0.23, 3., -1.2]) >>> ivy.sinh(x, out=x) >>> print(x) ivy.array([0.232, 10., -1.51])
With
ivy.NativeArray
input:>>> x = ivy.native_array([2, 4, 7]) >>> y = ivy.sinh(x) >>> print(y) ivy.array([3.63, 27.3, 548.])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([0.23, -0.25, 1]), b=ivy.array([3, -4, 1.26])) >>> y = ivy.sinh(x) >>> print(y) { a: ivy.array([0.232, -0.253, 1.18]), b: ivy.array([10., -27.3, 1.62]) }
- ivy.sqrt(x, /, *, out=None)[source]
Calculates the square root, having domain
[0, +infinity]
and codomain[0, +infinity]
, for each elementx_i
of the input arrayx
. After rounding, each result must be indistinguishable from the infinitely precise result (as required by IEEE 754).Special cases
For floating-point operands,
If
x_i
isNaN
, the result isNaN
.If
x_i
is less than0
, the result isNaN
.If
x_i
is+0
, the result is+0
.If
x_i
is-0
, the result is-0
.If
x_i
is+infinity
, the result is+infinity
.
- Parameters
- Return type
- Returns
ret – an array containing the square root of each element in
x
. The returned array must have a floating-point data type determined by type-promotion.This function conforms to the `Array API Standard
<https (//data-apis.org/array-api/latest/>`_. This docstring is an extension of the)
`docstring <https (//data-apis.org/array-api/latest/API_specification/generated/signatures.elementwise_functions.sqrt.html>`_ )
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.
Functional Examples
With
ivy.Array
input:>>> x = ivy.array([0, 4., 8.]) >>> y = ivy.sqrt(x) >>> print(y) ivy.array([0., 2., 2.83])
>>> x = ivy.array([1, 2., 4.]) >>> y = ivy.zeros(3) >>> ivy.sqrt(x, out=y) ivy.array([1., 1.41, 2.])
>>> X = ivy.array([40., 24., 100.]) >>> ivy.sqrt(x, out=x) >>> ivy.array([6.32455532, 4.89897949, 10.])
With
ivy.NativeArray
input:>>> x = ivy.native_array([-50., 1000., 34.]) >>> y = ivy.sqrt(x) >>> print(y) ivy.array([nan, 31.6, 5.83])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([44., 56., 169.]), b=ivy.array([[49.,1.], [0,20.]])) >>> y = ivy.sqrt(x) >>> print(y) { a: ivy.array([6.63, 7.48, 13.]), b: ivy.array([[7., 1.], [0., 4.47]]) }
Instance Method Examples
Using
ivy.Array
instance method:>>> x = ivy.array([[1., 2.], [3., 4.]]) >>> y = x.sqrt() >>> print(y) ivy.array([[1. , 1.41], [1.73, 2. ]])
Using
ivy.Container
instance method:>>> x = ivy.Container(a=ivy.array([0., 100., 27.]), b=ivy.native_array([93., 54., 25.])) >>> y = x.sqrt() >>> print(y) { a: ivy.array([0., 10., 5.2]), b: ivy.array([9.64, 7.35, 5.]) }
- ivy.square(x, /, *, out=None)[source]
Each element
x_i
of the input arrayx
.- Parameters
- Return type
- Returns
ret – an array containing the evaluated result for each element in
x
.This method conforms to the `Array API Standard
<https (//data-apis.org/array-api/latest/>`_. This docstring is an extension of the)
`docstring <https (//data-apis.org/array-api/latest/API_specification/generated/signatures.elementwise_functions.square.html>`_ )
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.
Functional Examples
With
ivy.Array
input:>>> x = ivy.array([1, 2, 3]) >>> y = ivy.square(x) >>> print(y) ivy.array([1, 4, 9])
>>> x = ivy.array([1.5, -0.8, 0.3]) >>> y = ivy.zeros(3) >>> ivy.square(x, out=y) >>> print(y) ivy.array([2.25, 0.64, 0.09])
>>> x = ivy.array([[1.2, 2, 3.1], [-1, -2.5, -9]]) >>> ivy.square(x, out=x) >>> print(x) ivy.array([[1.44,4.,9.61],[1.,6.25,81.]])
With :code: ivy.NativeArray input:
>>> a = ivy.native_array([1, 2, 3]) >>> b = ivy.square(a) >>> print(b) ivy.array([1, 4, 9])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([0, 1]), b=ivy.array([2, 3])) >>> y = ivy.square(x) >>> print(y) {a:ivy.array([0,1]),b:ivy.array([4,9])}
Instance Method Examples
With
ivy.Array
instance method:>>> x = ivy.array([1, 2, 3]) >>> y = x.square() >>> print(y) ivy.array([1, 4, 9])
With
ivy.Container
instance method:>>> x = ivy.Container(a=ivy.array([0, 1]), b=ivy.array([2, 3])) >>> y = x.square() >>> print(y) {a:ivy.array([0,1]),b:ivy.array([4,9])}
Operator Examples
With
ivy.Array
input:>>> x = ivy.array([1, 2, 3]) >>> y = x ** 2 >>> print(y) ivy.array([1, 4, 9])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([0, 1]), b=ivy.array([2, 3])) >>> y = x ** 2 >>> print(y) { a: ivy.array([0, 1]), b: ivy.array([4, 9]) }
- ivy.subtract(x1, x2, /, *, out=None)[source]
Calculates the difference for each element
x1_i
of the input arrayx1
with the respective elementx2_i
of the input arrayx2
.- Parameters
x1 (
Union
[float
,Array
,NativeArray
]) – first input array. Should have a numeric data type.x2 (
Union
[float
,Array
,NativeArray
]) – second input array. Must be compatible withx1
(see ref:broadcasting). Should have a numeric data type.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type
- Returns
ret – an array containing the element-wise differences.
- ivy.tan(x, /, *, out=None)[source]
Calculates an implementation-dependent approximation to the tangent, having domain
(-infinity, +infinity)
and codomain(-infinity, +infinity)
, for each elementx_i
of the input arrayx
. Each elementx_i
is assumed to be expressed in radians.Special cases
For floating-point operands,
If
x_i
isNaN
, the result isNaN
.If
x_i
is+0
, the result is+0
.If
x_i
is-0
, the result is-0
.If
x_i
is either+infinity
or-infinity
, the result isNaN
.
- Parameters
- Return type
- Returns
ret – an array containing the tangent of each element in
x
. The return must have a floating-point data type determined by type-promotion.
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
input:>>> x = ivy.array([0., 1., 2.]) >>> y = ivy.tan(x) >>> print(y) ivy.array([0., 1.56, -2.19])
>>> x = ivy.array([0.5, -0.7, 2.4]) >>> y = ivy.zeros(3) >>> ivy.tan(x, out=y) >>> print(y) ivy.array([0.546, -0.842, -0.916])
>>> x = ivy.array([[1.1, 2.2, 3.3], [-4.4, -5.5, -6.6]]) >>> ivy.tan(x, out=x) >>> print(x) ivy.array([[1.96, -1.37, 0.16], [-3.1, 0.996, -0.328]])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.])) >>> y = ivy.tan(x) >>> print(y) { a: ivy.array([0., 1.56, -2.19]), b: ivy.array([-0.143, 1.16, -3.38]) }
- ivy.tanh(x, /, *, out=None)[source]
Calculates an implementation-dependent approximation to the hyperbolic tangent, having domain
[-infinity, +infinity]
and codomain[-1, +1]
, for each elementx_i
of the input arrayx
.Special cases
For floating-point operands,
If
x_i
isNaN
, the result isNaN
.If
x_i
is+0
, the result is+0
.If
x_i
is-0
, the result is-0
.If
x_i
is+infinity
, the result is+1
.If
x_i
is-infinity
, the result is-1
.
- Parameters
- Return type
- Returns
ret – an array containing the hyperbolic tangent of each element in
x
. The returned array must have a real-valued floating-point data type determined by type-promotion.
This method conforms to the Array API Standard. This docstring is an extension of the docstring in the standard. The descriptions above assume an array input for simplicity, but the method also accepts
ivy.Container
instances in place ofivy.Array
orivy.NativeArray
instances, as shown in the type hints and also the examples below.Examples
With
ivy.Array
input:>>> x = ivy.array([0., 1., 2.]) >>> y = ivy.tanh(x) >>> print(y) ivy.array([0., 0.762, 0.964])
>>> x = ivy.array([0.5, -0.7, 2.4]) >>> y = ivy.zeros(3) >>> ivy.tanh(x, out=y) >>> print(y) ivy.array([0.462, -0.604, 0.984])
>>> x = ivy.array([[1.1, 2.2, 3.3], [-4.4, -5.5, -6.6]]) >>> ivy.tanh(x, out=x) >>> print(x) ivy.array([[0.8, 0.976, 0.997], [-1., -1., -1.]])
With
ivy.NativeArray
input:>>> x = ivy.native_array([0., 1., 2.]) >>> y = ivy.tanh(x) >>> print(y) ivy.array([0., 0.762, 0.964])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.])) >>> y = ivy.tanh(x) >>> print(y) { a: ivy.array([0., 0.762, 0.964]), b: ivy.array([0.995, 0.999, 1.]) }
- ivy.trunc(x, /, *, out=None)[source]
Rounds each element x_i of the input array x to the integer-valued number that is closest to but no greater than x_i.
Special cases
If
x_i
is already an integer-valued, the result isx_i
.
For floating-point operands,
If
x_i
is+infinity
, the result is+infinity
.If
x_i
is-infinity
, the result is-infinity
.If
x_i
is+0
, the result is+0
.If
x_i
is-0
, the result is-0
.If
x_i
isNaN
, the result isNaN
.
- Parameters
- Return type
- Returns
ret – an array containing the values before the decimal point for each element
x
. The returned array must have the same data type asx
.