December 2017
Intermediate to advanced
386 pages
10h 42m
English
When used with NumPy arrays, the * operator represents element by element multiplication, so it cannot be used to compute the matrix product. The matrix product of two arrays is computed with the dot() method of the ndarray object, as demonstrated in the following code:
A = np.array([[2.3, 4.5, -3.1], [1.2, 3.2, 4.0]])B = np.array([[ 2.1, -4.6, 0.5, 2.2], [-1.2, -3.0, 1.7, 3.2], [ 3.1, 2.6, 1.1, 2.3]])C = A.dot(B)
In this code segment, we first define two arrays, A and B, with shapes, respectively, of (2,3) and (3,4). Notice that the number of columns of A is equal to the number of rows of B, so that the matrix product AB is well-defined. The matrix product is computed with the statement C = A.dot(B), which outputs ...
Read now
Unlock full access