When I was a student, I desperately calculated the transpose matrix by hand, but if I use numpy, I can kill it instantly. great! !!
As an example, let's find the transposed matrix of a 3 × 3 matrix.
arr3d = np.arange(9).reshape((3, 3))
Then the following matrix is generated. ([[0, 1, 2], [3, 4, 5], [6, 7, 8]])
Next, find the transposed matrix. Just use the code below !!
arr3d.T
This alone ([[0, 3, 6], [1, 4, 7], [2, 5, 8]]) Will come out. This is easy.
after
arr3d.transpose()
Is the same, but .T is more stylish. Lol Unless you need to specify an argument, go with .T.
For matrix multiplication
np.dot(Matrix 1,Matrix 2)
Deke!
In the above
np.dot(arr.T, arr)
I will get the answer.
([[45, 54, 63], [54, 66, 78], [63, 78, 93]])
that's all.
Thank you to nyanko-box for pointing this out.
Recommended Posts