我在嘗試重塑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