【发布时间】:2018-08-27 06:37:36
【问题描述】:
我想将两个数组(a,b)(每个shape = (30,192,192,1))合并为一个(输入)像这样shape = (30,192,192,2)。
有没有人可以帮助我?
我的代码如下:
input = np.ndarray((a.shape[0], a.shape[1], a.shape[2],2))
input[:,:,:,0] = a
input[:,:,:,1] = b
但我收到此错误:
input[:,:,:,0] = a
ValueError: could not broadcast input array from shape (30,192,192,1) into shape (30,192,192)
【问题讨论】:
-
试试
input[:,:,:,[0]] = a,或input[:,:,:,0]=a[:,:,:,0]。即匹配形状。numpy广播可以在开头添加维度,而不是结尾。 -
非常感谢!效果很好!!!