![](/img/trans.png)
[英]In Python, given that there is a matrix, how do I print a slice of it?
[英]How do I copy a slice of a matrix and paste it to the end of the same matrix in Python?
我有一個大小為(21, 15, 50)
的矩陣,我想取矩陣的最后一層,大小為(1, 15, 50)
,我想復制該矩陣切片並將其粘貼回original 所以原始矩陣的大小為(22, 15, 50)
。 這將導致切片 21 和 22 具有相同的值。
我已經嘗試過np.hstack()
和append()
但我可能會錯誤地使用它們。
這個的語法是什么? 謝謝!
我稱您的 3d 陣列a
.
此代碼可能會解決您的問題:
a = np.concatenate((a, a[-1,:,:].reshape(1,15,50)), axis=0)
我試過並檢查了 a 的形狀,結果是你想要的(22,15,50)
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.