Let's transpose the matrix with numpy and multiply the matrices.

I have to take off my hat for the high operability of the numpy matrix.

When I was a student, I desperately calculated the transpose matrix by hand, but if I use numpy, I can kill it instantly. great! !!

Finish work with array.T!

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.

Finally, multiply the original matrix and the transposed matrix.

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

Let's transpose the matrix with numpy and multiply the matrices.
Matrix concatenation with Numpy
Try matrix operation with NumPy
See the power of speeding up with NumPy and SciPy
Let's create a PRML diagram with Python, Numpy and matplotlib.
Let's move word2vec with Chainer and see the learning progress
Performance comparison between 2D matrix calculation and for with numpy
HTTPS with Django and Let's Encrypt
[Python3] Save the mean and covariance matrix in json with pandas
Solving with Ruby, Python and numpy AtCoder ABC054 B Matrix operation
Find the inertial spindle and moment of inertia from the inertial tensor with NumPy
Let's tune the model hyperparameters with scikit-learn!
Let's solve the portfolio with continuous optimization
Let's try gRPC with Go and Docker
Let's read the RINEX file with Python ①
Read and write csv files with numpy
Graph trigonometric functions with numpy and matplotlib
Comparison of matrix transpose speeds with Python
Let's play with Python Receive and save / display the text of the input form
Let's print PDF with python using foxit reader and specify the printer silently!
Let's visualize the relationship between average salary and industry with XBRL data and seaborn! (7/10)
Scraping the holojour and displaying it with CLI
Find a position above the threshold with NumPy
Numpy leave? !! Partial differential of matrix with Sympy
Let's control EV3 motors and sensors with Python
Solving the Lorenz 96 model with Julia and Python
Archive and compress the entire directory with python
Describe ec2 with boto3 and retrieve the value
[All-new best browser] Let's change the way the Internet works and how it works with the Brave browser.