multiply
Description
Multiply arguments element-wise.
Mandatory Input Parameters
Parameter |
Type |
Description |
|---|---|---|
x1, x2 |
array_like |
Input arrays or scalars to be multiplied. If x1.shape!=x2.shape, they must be broadcastable to a common shape. |
Optional Input Parameters
Return Value
Type |
Description |
|---|---|
ndarray/scalar |
Product of x1 and x2, element-wise |
Examples
>>> import numpy as np
>>> np.multiply(1.1, 5.5)
6.050000000000001
>>> x1 = np.arange(9.0).reshape((3,3))
>>> x2 = np.arange(3.0)
>>> x1
array([[0., 1., 2.],
[3., 4., 5.],
[6., 7., 8.]])
>>> x2
array([0., 1., 2.])
>>>
>>> np.multiply(x1, x2)
array([[ 0., 1., 4.],
[ 0., 4., 10.],
[ 0., 7., 16.]])
>>
# If both x1 and x2 are of the ndarray type, you can use * to replace np.multiply.
>>> x1 = np.arange(0, 4).reshape((2,2))
>>> x1
array([[0, 1],
[2, 3]])
>>> x2 = np.arange(4, 8).reshape((2,2))
>>> x2
array([[4, 5],
[6, 7]])
>>>
>>> x1 * x2
array([[ 0, 5],
[12, 21]])
>>>
Parent topic: Basic Operation Functions