Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize Matrix Multiplication by python

Shulou Source: shulou.com Published: 2022-06-02 02:31:12 10月28日 Update

Editor to share with you how to achieve matrix multiplication in python. I hope you will get something after reading this article. Let's discuss it together.

Matrix multiplication requires that the number of rows of the front matrix is the same as the number of columns of the following matrix before multiplying. In the first step, each row of the front matrix is multiplied by the column of the following matrix as the column of the result matrix; the second step is to calculate the result.

# 2 3 3 "12" 4 5 "12 3" 5 6 7 "9 10 11 12lst1, lst2 = [], [] N1 map m1Powerm2 = map (int,input (). Split ()) for i in range (N1): nums = list (map (int,input (). Split ()) # enter a row of data lst1.append (nums) for i in range (N2): nums = list (int (int) Input (). Split ()) lst2.append (nums) res = [] for i in range (N1): res.append ([]) for j in range (m2): lst4 = [] lst3 = lst1 [I] for k in range (N2): lst4.append (LST2 [k] [j]) res_num = sum (map (lambda XMagux for k in range) Lst4) res [I] .append (res_num) print (res) import numpy as npprint ('numpy:',np.dot (lst1,lst2)) # using numpy verification results 2 3 3 41 2 34 5 61 2 3 45 6 7 89 10 11 12 [[38, 44, 50, 56], [83, 98, 113, 128]] numpy: [38 44 50 56] [83 98 113 128]] read this article I believe you have a certain understanding of "how to achieve matrix multiplication in python". If you want to know more about it, please follow the industry information channel. Thank you for your reading!

Tags: Matrix result multiplication one line article same finished data more knowledge industry ranks information information channel channel first input verify Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Docker OPPO Reno macOS vpn