我在尝试重塑3D numpy数组时遇到了一个奇怪的错误。Python Numpy Reshape Error
数组(x)具有形状(6,10,300),我想将其重塑为(6,3000)。
我使用下面的代码:
reshapedArray = np.reshape(x, (x.shape[0], x.shape[1]*x.shape[2]))
我收到的错误是:
TypeError: only integer scalar arrays can be converted to a scalar index
但是,如果我把x转换成一个列表,它的工作原理:
x = x.tolist()
reshapedArray = np.reshape(x, (len(x), len(x[0])*len(x[0][0])))
你有什么想法,为什么这可能是?
提前致谢!
编辑:
这是我运行的是代码和产生错误
x = np.stack(dataframe.as_matrix(columns=['x']).ravel())
print("OUTPUT:")
print(type(x), x.dtype, x.shape)
print("----------")
x = np.reshape(x, (x.shape[0], x.shape[1]*x[2]))
OUTPUT:
<class 'numpy.ndarray'> float64 (6, 10, 300)
----------
TypeError: only integer scalar arrays can be converted to a scalar index
你可以报告:'type(x)'和'x.dtype'? – Divakar
type = dtype = float64 –
SirTobi
如果您执行'np.reshape(x,(x.shape [0],-1))',并且它的工作原理是什么形状,会发生什么?有? – MSeifert