Add, subtract, multiply NumPy array

In Python, a vector can be expressed by NumPy array.

import numpy as np

v = np.array([1, 3.1])
v1 = -v
v2 = v * 2
v3 = v * (-3)
v4 = v + v
v5 = v - v

print(v1)  # [-1.  -3.1]
print(v2)  # [2.  6.2]
print(v3)  # [-3.  -9.3]
print(v4)  # [2.  6.2]
print(v5)  # [0. 0.]

NumPy array can be added, subtracted, multiplied. * symbol must be written clearly to work multiplying.

NumPy Array

NumPy Tutorial