網站首頁 編程語言 正文
1、文檔
使用numpy的 concatenate 拼接矩陣,文檔里面這樣解釋:
numpy.concatenate((a1, a2, ...), axis=0, out=None, dtype=None, casting="same_kind")
(a1, a2, ...):連接的數組必須有一樣的維度;
axis:拼接的方向;
out:預設輸出矩陣的大小
…………
2、舉例
首先給定兩個矩陣:
rotation = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
trans = np.array([[7],
[8],
[0]])
①:在第一個矩陣后面加上第二個矩陣(加一列):
z = np.concatenate((rotation, trans), axis=1)
輸出為:
[[1 2 3 7]
?[4 5 6 8]
?[7 8 9 0]]
②:以及在矩陣下面加一個全零行:
add_arr = np.array([[0, 0, 0, 0]])
array_by_add = np.concatenate((z, add_arr), axis=0)
輸出:
[[1 2 3 7]
?[4 5 6 8]
?[7 8 9 0]
?[0 0 0 0]]
③:把矩陣填充為對角矩陣:
第一個為3×3矩陣,第二個為2×3矩陣。
arr1 = np.array([[2, 3, 4],
[3, 4, 5],
[4, 5, 6]])
arr2 = np.array([[7, 8, 9],
[8, 9, 10]])
arr_zeros1 = np.zeros((arr2.shape[1], arr1.shape[0]))
print(arr_zeros1)
arr_zeros2 = np.zeros((arr2.shape[0], arr1.shape[1]))
print(arr_zeros2)
total_arr1 = np.concatenate((arr1, arr_zeros1), axis=1)
total_arr2 = np.concatenate((arr_zeros2, arr2,), axis=1)
total_arr = np.concatenate((total_arr1, total_arr2), axis=0)
print(total_arr)
拼接之后結果如下:
[5 6]
[[0. 0. 0.]
?[0. 0. 0.]
?[0. 0. 0.]]
[[0. 0. 0.]
?[0. 0. 0.]]
[[ 2. ?3. ?4. ?0. ?0. ?0.]
?[ 3. ?4. ?5. ?0. ?0. ?0.]
?[ 4. ?5. ?6. ?0. ?0. ?0.]
?[ 0. ?0. ?0. ?7. ?8. ?9.]
?[ 0. ?0. ?0. ?8. ?9. 10.]]
官方文檔地址:numpy官網地址
原文鏈接:https://blog.csdn.net/Arhonbt/article/details/125746727
相關推薦
- 2022-12-23 解讀pandas.DataFrame.corrwith_python
- 2022-09-27 Python?Matplotlib繪制扇形圖標簽重疊問題解決過程_python
- 2022-08-18 詳解如何從Matlab中導出清晰的結果圖片_C 語言
- 2022-05-02 winform關閉窗體FormClosing事件用法介紹_C#教程
- 2023-01-14 Linux命令行查看cpu(lm_sensors)和顯卡溫度(nvidia-smi)的操作方法_li
- 2022-08-29 Python軟件包安裝的三種常見方法_python
- 2022-11-20 更強大的React?狀態管理庫Zustand使用詳解_React
- 2024-01-14 Spring boot 注解@Async不生效 無效 不起作用
- 最近更新
-
- 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同步修改后的遠程分支