Since python3.5, the product AB of matrix A and matrix B is calculated using the @ operator. A@B I came to be able to write. By using this @ operator, readability in coding is improved. However, as you can see in the code below, you need to ** generate matrices A and B as matrix objects instead of array objects **.
import numpy as np
"""
Matrix multiplication
C = A B
"""
#Make a matrix A
a1_lis = [1, 0, 0]
a2_lis = [0, 2, 0]
a3_lis = [0, 0, 4]
A_matrix=np.matrix([a1_lis, a2_lis, a3_lis])# "np.array"not,"np.matrix"Generate a matrix object as
#Make a matrix B
b1_lis = [3, 0, 0]
b2_lis = [1, 2, 0]
b3_lis = [1, 0, 4]
B_matrix=np.matrix([b1_lis, b2_lis, b3_lis]) #
C_matrix = A_matrix @ B_matrix C =Calculation of A B
print(C_matrix)
[[ 3 0 0] [ 2 4 0] [ 4 0 16]]
When the matrices A and B are generated as array objects instead of matrix objects (let's say np.array ()), Of the code above C_matrix = A_matrix @ B_matrix
The part of should be written as follows.
C_matrix = A_matrix.dot(B_matrix)