![]() |
VOOZH | about |
In Python, NumPy provides a way to compute matrix multiplication using numpy.dot() function. This method calculates dot product of two arrays, which is equivalent to matrix multiplication.
For example:
Suposse there are two matrices A and B.
A = [[1, 2], [2, 3]]
B = [[4, 5], [6, 7]]
So, A.B = [[1*4 + 2*6, 2*4 + 3*6], [1*5 + 2*7, 2*5 + 3*7]
Result: [[16, 26], [19, 31]]
Example 1: This example demonstrates the multiplication of two 2x2 square matrices using np.dot().
Matrix A: [[1, 2], [2, 3]] Matrix B: [[4, 5], [6, 7]] Result: [[16 19] [26 31]]
Explanation: np.dot(a, b) multiplies matrices a and b using the dot product rule:
Example 2: This example shows multiplication of a 3x2 matrix with a 2x3 matrix, producing a 3x3 result.
Matrix X: [[1, 2], [2, 3], [4, 5]] Matrix Y: [[4, 5, 1], [6, 7, 2]] Result: [[16 19 5] [26 31 8] [46 55 14]]
Explanation: