August 2019
Intermediate to advanced
342 pages
9h 35m
English
To fully understand the use of the dot() method of NumPy in matrix multiplication operations, we can try to implement a simple predictor from scratch, to predict future values starting from a set of multiple inputs and on the basis of relative weights, using the product between matrices and vectors:
import numpy as npdef predict(data, w): return data.dot(w)
# w is the vector of weightsw = np.array([0.1, 0.2, 0.3])
# matrices as input datasetsdata1 = np.array([0.3, 1.5, 2.8])
data2 = np.array([0.5, 0.4, 0.9])
data3 = np.array([2.3, 3.1, 0.5])data_in = np.array([data1[0],data2[0],data3[0]]) print('Predicted value: $%.2f' % predict(data_in, w) )
Read now
Unlock full access