[英]Number of 2D array to 3D array, extending third dimension
I have 10 different matrix of size (60, 100)
. 我有10个不同的矩阵
(60, 100)
。 I want to put them along the third dimension inside a for loop, so that the final shape is (10, 60, 100)
. 我想把它们放在for循环中的第三个维度,这样最终的形状是
(10, 60, 100)
。
I tried with concatenate and end up with size (600, 100)
. 我尝试连接并最终得到大小
(600, 100)
。
numpy.stack
will allow you to concatenate along new axis. numpy.stack
将允许您沿新轴连接。
arrays = [mat1,mat2,.....]
out=np.stack(arrays, axis=0)
Try creating a new array that you fill with your 2D arrays 尝试创建一个用二维数组填充的新数组
new3DArray = numpy.empty(10, 60, 100)
new3DArray = numpy.empty(10,60,100)
@MahmoudGeMy answer is my favorite. @MahmoudGeMy答案是我最喜欢的。 But there is also another way for reference:
但还有另一种参考方式:
out = np.concatenate((mat1[np.newaxis,:],mat1[np.newaxis,:],...),axis=0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.