【发布时间】:2019-05-03 18:20:49
【问题描述】:
我有一个 3D 数组,一个:
`print(a.shape)
In [1]:(4, 4571, 8893)
b = a.reshape(a.shape[2]*a.shape[1],a.shape[0]) # Here I've also tried changing the shape of with (a.shape[2]*a.shape[1],a.shape[0])
print(b.shape)
In [2]:(40649903, 4)
c=some_function(b) # returns c which has same shape as b.shape[0]
print(c.shape)
In [2]: (40649903,)
d = c.reshape(a.shape[1],a.shape[2]) # same shape as a.shape[1:]
print(d.shape)
In [3]:(4571, 8893)
`
现在当我看 d 时,我得到一个像这样的形状:
plt.imshow(d)
但它必须像下面显示的图像(请忽略颜色,黄色区域的形状必须像海军蓝色区域):
plt.imshow(a[0])
也许这与重塑轴有关,但我无法弄清楚我在哪里使用了错误的轴来重塑。我对此进行了一些思考,并阅读了 numpy 文档,但文档和在线示例(SO 问题)似乎没有针对我的具体问题的干净示例。我所缺少的任何方向都会有所帮助。
【问题讨论】:
-
用一些小东西做实验,比如 np.arange(24.reshape(4,3,2)。reshape to (4,6) 与 reshape to (6,4) 完全不同。跨度>
-
好主意,谢谢!没想到!!
标签: python arrays numpy reshape