[英]np.concatenate a list of numpy.ndarray in new dimension?
I have a list with numpy.ndarrays - each of shape (33,1,8,45,3)
我有一个带有numpy.ndarrays的列表-每个形状(33,1,8,45,3)
Problem that when i concatenate the list using a = np.concatenate(list)
The output shape of a becomes 问题是,当我使用a = np.concatenate(list)
连接列表时,a的输出形状变为
print a.shape
(726,1,8,45,3)
instead of shape (22,33,1,8,45,3)
. 而不是形状(22,33,1,8,45,3)
。
How do I cleanly concatenate the list, without having to change the input. 我如何干净地串联列表,而不必更改输入。
np.concatenate
: np.concatenate
:
Join a sequence of arrays along an existing axis . 沿现有轴连接一系列数组。
Stack a sequence of arrays along a new axis . 沿新轴堆叠一系列数组。
a = np.ones((3, 4))
b = np.stack([a, a])
print(b.shape) # (2, 3, 4)
You can use numpy.array()
or numpy.stack()
: 您可以使用numpy.array()
或numpy.stack()
:
import numpy
a = [numpy.random.rand(33,1,8,45,3) for i in range(22)]
b = numpy.array(a)
b.shape # (22, 33, 1, 8, 45, 3)
c = numpy.stack(a, axis=0)
c.shape # (22, 33, 1, 8, 45, 3)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.