The multiply() function multiplies the values from one array by the values from another array and returns the results in a new array.
Multiply the values in arr1 by the values in arr2:
import numpy as np arr1 = np.array([10, 20, 30, 40, 50, 60]) arr2 = np.array([20, 21, 22, 23, 24, 25]) newarr = np.multiply(arr1, arr2) print(newarr) |
The example above will yield [200, 420, 660, 920, 1200, 1500] , which results from 10×2010 \times 20, 20×2120 \times 21, 30×2230 \times 22, and so on. |
The divide() function divides the values in one array by the corresponding values in another array and returns the results in a new array.
Divide the values in arr1 by the values in arr2:
import numpy as np arr1 = np.array([10, 20, 30, 40, 50, 60]) arr2 = np.array([3, 5, 10, 8, 2, 33]) newarr = np.divide(arr1, arr2) print(newarr) |
The example above will produce [3.33333333, 4., 3., 5., 25., 1.81818182] , which results from 10/310/3, 20/520/5, 30/1030/10, and so forth. |