Curriculum
Course: NumPy
Login

Curriculum

NumPy

Text lesson

Subtraction

Subtraction

The subtract() function takes the values from one array and subtracts the corresponding values from another array, returning the results in a new array.

Example

Subtract the values in arr2 from the values in arr1:

import numpy as np

arr1 = np.array([102030405060])
arr2 = np.array([202122232425])

newarr = np.subtract(arr1, arr2)

print(newarr)
The example above will produce [-10, -1, 8, 17, 26, 35], which results from 10−2010 – 2020−2120 – 2130−2230 – 22, and so forth.