In addition to being mathematical entities studied in linear algebra, Vectors are widely used in physics and engineering as a convenient way to represent physical quantities as displacement, velocity, acceleration, force, and so on. Accordingly, basic operations between vectors can be performed via Numpy/SciPy operations as follows:
Addition/subtraction of vectors does not require any explicit loop to perform them. Let's take a look at addition of two vectors:
>>> vectorC = vectorA + vectorB >>> vectorC
The output is shown as follows:
array([8, 8, 8, 8, 8, 8, 8])
Further, we perform subtraction on two vectors:
>>> vectorD = vectorB - vectorA >>> vectorD
The output is shown as follows:
array([ 6, 4, 2, 0, -2, -4, -6])