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])))
これがなぜ起こり得るのかご存知ですか?
ありがとうございます!
編集:
これは私が実行しているコードであり、それはreshape
のための第二引数の一つの要素が整数でない場合は、例外が唯一のため、起こるはずのエラー
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