The subtract() function takes the values from one array and subtracts the corresponding values from another array, returning the results in a new array.
Subtract the values in arr2 from the values in arr1:
import numpy as np arr1 = np.array([10, 20, 30, 40, 50, 60]) arr2 = np.array([20, 21, 22, 23, 24, 25]) newarr = np.subtract(arr1, arr2) print(newarr) |
The example above will produce [-10, -1, 8, 17, 26, 35] , which results from 10−2010 – 20, 20−2120 – 21, 30−2230 – 22, and so forth. |