【发布时间】:2019-07-03 21:07:41
【问题描述】:
我正在尝试做这个人正在做的事情numpy: extending arrays along a new axis?,但我不想在新维度中重复相同的数组。我正在生成一个新的 2D 数组,并希望将其附加到第 3 维
我尝试过使用 np.stack((a,b), axis=2) 但数组的形状必须相同。所以在它堆叠前两个数组之后,第二次迭代的形状是 (256, 256, 2) 和 (256, 256) 我得到 ValueError: all input arrays must have the same shape
a = something #a has shape (256, 256)
for i in np.arange(0,10):
#calculate b and it also has shape (256,256)
a = np.stack((a,b), axis=2)
print(a.shape) #should give (256, 256, 10)
【问题讨论】:
标签: numpy-ndarray