網站首頁 編程語言 正文
矩陣相乘需要前面矩陣的行數與后面矩陣的列數相同方可相乘。第一步,先將前面矩陣的每一行分別與后面矩陣的列相乘,作為結果矩陣的行列;第二步算出結果即可。
# 2 3 3 4 # 1 2 3 # 4 5 6 # 1 2 3 4 # 5 6 7 8 # 9 10 11 12 lst1, lst2 = [], [] n1,m1,n2,m2 = map(int,input().split()) for i in range(n1): ? ? nums = list(map(int,input().split())) #輸入一行數據 ? ? lst1.append(nums) for i in range(n2): ? ? nums = list(map(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 x,y:x*y,lst3,lst4)) ? ? ? ? res[i].append(res_num) print(res) import numpy as np print('numpy:',np.dot(lst1,lst2)) #使用numpy驗證結果
2 3 3 4 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 10 11 12 [[38, 44, 50, 56], [83, 98, 113, 128]] numpy: [[ 38 ?44 ?50 ?56] ?[ 83 ?98 113 128]]
原文鏈接:https://blog.csdn.net/EMIvv/article/details/122379301
相關推薦
- 2022-09-22 NCL:Improving Graph Collaborative Filtering with N
- 2023-02-26 flutter中的網絡請求數據獲取詳解_Android
- 2022-05-02 C/C++的各種字符串函數你知道幾個_C 語言
- 2022-04-30 Winform項目中TextBox控件DataBindings屬性_C#教程
- 2022-04-14 Python實現簡單購物車小程序_python
- 2022-04-23 .NET?Core使用APB?vNext框架入門教程_實用技巧
- 2022-06-24 PyTorch中permute的基本用法示例_python
- 2022-12-23 C++類的返回值是*this的成員函數問題_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支