Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从Python numpy 3D数组到2D再到1D再到2D(保留3D数组的原始第二和第三维)_Python_Arrays_Numpy_Reshape - Fatal编程技术网

如何从Python numpy 3D数组到2D再到1D再到2D(保留3D数组的原始第二和第三维)

如何从Python numpy 3D数组到2D再到1D再到2D(保留3D数组的原始第二和第三维),python,arrays,numpy,reshape,Python,Arrays,Numpy,Reshape,我有一个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

我有一个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)

但它必须像下图所示(pl.忽略颜色,黄色区域的形状必须像海军蓝区域):


也许这与重塑轴有关,但我无法确定在哪里使用了错误的轴来重塑。我对此做了一些思考,并阅读了numpy文档,但是文档和在线示例(所以问题)似乎没有针对我的具体问题的清晰示例。任何我错过的方向都会有帮助

以下是其他可能有同样问题的人的答案:

a = np.arange(24).reshape(4,3,2)
print(a); print(a.shape)

b = a.reshape(a.shape[0],a.shape[1]*a.shape[2]).T; 
print(b); print(b.shape) # X

c = a[0].flatten() # Y
print(c); print(c.shape)

d = c.reshape(a[1].shape); 
print(d); print(d.shape) # same as print(a[0].shape)

谢谢你的建议@hpaulj

尝试一些小东西,比如np.arange(24.重塑(4,3,2)。重塑为(4,6)与重塑为(6,4)完全不同。好主意,谢谢!我没想到!!
a = np.arange(24).reshape(4,3,2)
print(a); print(a.shape)

b = a.reshape(a.shape[0],a.shape[1]*a.shape[2]).T; 
print(b); print(b.shape) # X

c = a[0].flatten() # Y
print(c); print(c.shape)

d = c.reshape(a[1].shape); 
print(d); print(d.shape) # same as print(a[0].shape)