MULTIPLYING LISTS AND ARRAYS
Listing 2.5 displays the content of multiply1.py that illustrates how to multiply elements in a Python list and a NumPy array.
LISTING 2.5: multiply1.py
import numpy as np
list1 = [1,2,3]
arr1 = np.array([1,2,3])
print('list: ',list1)
print('arr1: ',arr1)
print('2*list:',2*list)
print('2*arr1:',2*arr1)
Listing 2.5 contains a Python list called list and a NumPy array called arr1. The print() statements display the contents of list1 and arr1, as well as the result of doubling list1 and arr1. Recall that “doubling” a Python list is different from doubling a Python array, which you can see in the output from launching Listing 2.5:
('list: ', [1, 2, 3])
('arr1: ', array([1, 2, 3]))
('2*list:', [1, 2, 3, 1, 2, 3])
('2*arr1:', array([2, 4, 6]))