divide#
- ivy.divide(x1, x2, /, *, out=None)[source]#
Calculate 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.
This method conforms to the Array API Standard. This docstring is an extension of the docstring # noqa in the standard.
Both the description and the type hints above assumes an array input for simplicity, but this function is nestable, and therefore also accepts
ivy.Container
instances in place of any of the arguments.Examples
With
ivy.Array
inputs:>>> x1 = ivy.array([2., 7., 9.]) >>> x2 = ivy.array([3., 4., 0.6]) >>> y = ivy.divide(x1, x2) >>> print(y) ivy.array([0.667, 1.75, 15.])
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]) }
- Array.divide(self, x2, /, *, out=None)#
ivy.Array instance method variant of ivy.divide. This method simply wraps the function, and so the docstring for ivy.divide also applies to this method with minimal changes.
- Parameters:
self (
Array
) – dividend input array. Should have a real-valued data type.x2 (
Union
[Array
,NativeArray
]) – divisor input array. Must be compatible withself
(see broadcasting). Should have a real-valued data type.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that (default:None
) the inputs broadcast to.
- Return type:
Array
- 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:>>> x1 = ivy.array([2., 7., 9.]) >>> x2 = ivy.array([2., 2., 2.]) >>> y = x1.divide(x2) >>> print(y) ivy.array([1., 3.5, 4.5])
With mixed
ivy.Array
and ivy.NativeArray inputs:>>> x1 = ivy.array([2., 7., 9.]) >>> x2 = ivy.native_array([2., 2., 2.]) >>> y = x1.divide(x2) >>> print(y) ivy.array([1., 3.5, 4.5])
- Container.divide(self, x2, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)#
ivy.Container instance method variant of ivy.divide. This method simply wraps the function, and so the docstring for ivy.divide also applies to this method with minimal changes.
- Parameters:
self (
Container
) – dividend input array or container. Should have a real-valued data type.x2 (
Union
[Container
,Array
,NativeArray
]) – divisor input array or container. Must be compatible withself
(see broadcasting). Should have a real-valued data type.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
]]]) – The key-chains to apply or not apply the method to. Default isNone
. (default:None
)to_apply (
bool
) – If True, the method will be applied to key_chains, otherwise key_chains (default:True
) will be skipped. Default isTrue
.prune_unapplied (
bool
) – Whether to prune key_chains for which the function was not applied. (default:False
) Default isFalse
.map_sequences (
bool
) – Whether to also map method to sequences (lists, tuples). (default:False
) Default isFalse
.out (
Optional
[Container
]) – optional output container, for writing the result to. It must have a shape (default:None
) that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – a container containing the element-wise results. The returned container must have a data type determined by type-promotion.
Examples
With
ivy.Container
inputs:>>> x1 = ivy.Container(a=ivy.array([12., 3.5, 6.3]), b=ivy.array([3., 1., 0.9])) >>> x2 = ivy.Container(a=ivy.array([1., 2.3, 3]), b=ivy.array([2.4, 3., 2.])) >>> y = x1.divide(x2) >>> print(y) { a: ivy.array([12., 1.52, 2.1]), b: ivy.array([1.25, 0.333, 0.45]) }
With
Number
instances at the leaves:>>> x = ivy.Container(a=1, b=2) >>> y = ivy.Container(a=5, b=4) >>> z = x.divide(y) >>> print(z) { a: 0.2, b: 0.5 }