1.

How do you multiply 2 NumPy array matrices?

Answer»

We can make use of the dot() for multiplying matrices represented as NumPy arrays. This is represented in the code snippet below:

import numpy as np

# NumPy matrices
A = np.arange(15,24).reshape(3,3)
B = np.arange(20,29).reshape(3,3)
print("A: ",A)
print("B: ",B)

# Multiply A and B
result = A.dot(B)
print("Result: ", result)

Output

A: [[15 16 17]
[18 19 20]
[21 22 23]]
B: [[20 21 22]
[23 24 25]
[26 27 28]]
Result: [[1110 1158 1206]
[1317 1374 1431]
[1524 1590 1656]]


Discussion

No Comment Found