[英]How do I copy a slice of a matrix and paste it to the end of the same matrix in Python?
I have a matrix of size (21, 15, 50)
and I want to take the last level of the matrix which would be a size (1, 15, 50)
and I want to copy that matrix slice and paste it back to the original so then the original matrix would have a size of (22, 15, 50)
.我有一个大小为(21, 15, 50)
的矩阵,我想取矩阵的最后一层,大小为(1, 15, 50)
,我想复制该矩阵切片并将其粘贴回original 所以原始矩阵的大小为(22, 15, 50)
。 This would result in slices 21 and 22 to have the same values.这将导致切片 21 和 22 具有相同的值。
I have tried np.hstack()
and append()
but I could be using them incorrectly.我已经尝试过np.hstack()
和append()
但我可能会错误地使用它们。
What is the syntax for this?这个的语法是什么? Thank you!谢谢!
I call your 3d array is a
.我称您的 3d 阵列a
.
This code may solve your problem:此代码可能会解决您的问题:
a = np.concatenate((a, a[-1,:,:].reshape(1,15,50)), axis=0)
I have tried and checked the shape of a, the result is (22,15,50)
as you want.我试过并检查了 a 的形状,结果是你想要的(22,15,50)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.