Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Matrix Multiplication by python

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report