ARRAYS AND VECTOR OPERATIONS
Listing 2.12 displays the content of array_vector.py that illustrates how to perform vector operations on the elements in a NumPy array.
LISTING 2.12: array_vector.py
import numpy as np
a = np.array([[1,2], [3, 4]])
b = np.array([[5,6], [7,8]])
print('a: ', a)
print('b: ', b)
print('a + b: ', a+b)
print('a - b: ', a-b)
print('a * b: ', a*b)
print('a / b: ', a/b)
print('b / a: ', b/a)
print('a.dot(b):',a.dot(b))
Listing 2.12 contains two NumPy arrays called a and b followed by eight print() statements, each of which displays the result of “applying” a different arithmetic operation to the NumPy arrays a and b. The output from launching Listing 2.12 is here:
('a : ', array([[1, 2], [3, 4]]))
('b : ', array([[5, 6], [7, 8]]))
('a + b: ', array([[ 6, 8], [10, 12]]))
('a - b: ', array([[-4...