import numpy as np arr = np.array([1, 2, 3]) mat = np.array([[1, 2, 3], [4, 6, 5], [7, 8, 9]]) # Multiplication of array and matrix, without the use of for loops prod1 = arr * mat # Multiplication of matrix * transposed array # (should be equal to previous answer) prod2 = mat * np.transpose(arr) prod3 = 3 * prod1 # Elementwise multiplication prod4 = prod1.dot(prod2) # Matrixwise multiplication # Matrixwise multiplication of matrix with its inverse should lead # to identity matrix (with almost-zeros off the diagonal). prod5 = np.dot(mat, np.linalg.inv(mat)) # Identity creates an identity matrix. prod6 = np.identity(3) # Creating, then reshaping an array m= np.arange(10).reshape(2,5) print('Initial array = \n', arr) print('Initial matrix = \n', mat) print('prod1 = \n', prod1) print('prod2 = \n', prod2) print('prod3 = \n', prod3) print('prod4 = \n', prod4) print('prod5 = \n', prod5) print('prod6 = \n', prod6) print('m = \n', m)