multiply#
- ivy.multiply(x1, x2, /, *, out=None)[source]#
Calculate the product 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. 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 typeout (
Optional
[Array
]) – optional output array, for writing the array result to. (default:None
) It must have a shape that the inputs broadcast to.Standard (This function conforms to the `Array API) –
<https (`docstring) –
<https –
standard. (in the) –
simplicity (Both the description and the type hints above assumes an array input for) –
:param : :param but this function is nestable: :param and therefore also accepts
ivy.Container
: :param instances in place of any of the arguments.:- Return type:
- Returns:
ret – an array containing the element-wise products. The returned array must have a data type determined by Type Promotion Rules.
Examples
With
ivy.Array
inputs:>>> x1 = ivy.array([3., 5., 7.]) >>> x2 = ivy.array([4., 6., 8.]) >>> y = ivy.multiply(x1, x2) >>> print(y) ivy.array([12., 30., 56.])
With
ivy.NativeArray
inputs:>>> x1 = ivy.native_array([1., 3., 9.]) >>> x2 = ivy.native_array([4., 7.2, 1.]) >>> y = ivy.multiply(x1, x2) >>> print(y) ivy.array([ 4. , 21.6, 9. ])
With mixed
ivy.Array
andivy.NativeArray
inputs:>>> x1 = ivy.array([8., 6., 7.]) >>> x2 = ivy.native_array([1., 2., 3.]) >>> y = ivy.multiply(x1, x2) >>> print(y) ivy.array([ 8., 12., 21.])
With
ivy.Container
inputs:>>> x1 = ivy.Container(a=ivy.array([12.,4.,6.]), b=ivy.array([3.,1.,5.])) >>> x2 = ivy.Container(a=ivy.array([1.,3.,4.]), b=ivy.array([3.,3.,2.])) >>> y = ivy.multiply(x1, x2) >>> print(y) { a: ivy.array([12.,12.,24.]), b: ivy.array([9.,3.,10.]) }
With mixed
ivy.Container
andivy.Array
inputs:>>> x1 = ivy.Container(a=ivy.array([3., 4., 5.]), b=ivy.array([2., 2., 1.])) >>> x2 = ivy.array([1.,2.,3.]) >>> y = ivy.multiply(x1, x2) >>> print(y) { a: ivy.array([3.,8.,15.]), b: ivy.array([2.,4.,3.]) }
- Array.multiply(self, x2, /, *, out=None)#
ivy.Array instance method variant of ivy.multiply. This method simply wraps the function, and so the docstring for ivy.multiply also applies to this method with minimal changes.
- Parameters:
self (
Array
) – first input array. Should have a real-valued data type.x2 (
Union
[Array
,NativeArray
]) – second input array. Must be compatible with the first input array. (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 products. The returned array must have a data type determined by type-promotion.
Examples
With
ivy.Array
inputs:>>> x1 = ivy.array([3., 5., 7.]) >>> x2 = ivy.array([4., 6., 8.]) >>> y = x1.multiply(x2) >>> print(y) ivy.array([12., 30., 56.])
With mixed
ivy.Array
and ivy.NativeArray inputs:>>> x1 = ivy.array([8., 6., 7.]) >>> x2 = ivy.native_array([1., 2., 3.]) >>> y = x1.multiply(x2) >>> print(y) ivy.array([ 8., 12., 21.])
- Container.multiply(self, x2, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)#
ivy.Container instance method variant of ivy.multiply. This method simply wraps the function, and so the docstring for ivy.multiply also applies to this method with minimal changes.
- Parameters:
self (
Container
) – first input array or container. Should have a numeric data type.x2 (
Union
[Container
,Array
,NativeArray
]) – second input array or container. Must be compatible withself
(see broadcasting). Should have a nuneric 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 products. The returned container must have a data type determined by type-promotion.
Examples
With
ivy.Container
inputs:>>> x1 = ivy.Container(a=ivy.array([15., 4.5, 6.5]), b=ivy.array([3.2, 5., 7.5])) >>> x2 = ivy.Container(a=ivy.array([1.7, 2.8, 3.]), b=ivy.array([5.6, 1.2, 4.2])) >>> y = ivy.Container.multiply(x1, x2) >>> print(y) { a: ivy.array([25.5, 12.6, 19.5]), b: ivy.array([17.9, 6., 31.5]) }
With mixed
ivy.Container
andivy.Array
inputs:>>> x1 = ivy.Container(a=ivy.array([6.2, 4.8, 2.3]), b=ivy.array([5., 1.7, 0.1])) >>> x2 = ivy.array([8.3, 3.2, 6.5]) >>> y = ivy.Container.multiply(x1, x2) >>> print(y) { a: ivy.array([51.5, 15.4, 14.9]), b: ivy.array([41.5, 5.44, 0.65]) }