numpyとkerasを使ってディープラーニングのモデルを作っているのですが、あまりnumpyに関する知識がないのであまり前に進めずにいます。
困っていることはタイトルのとおりなのですが、こんなコードが有りました。
python
1mnist = datasets.fetch_mldata('MNIST original', data_home='.') 2 3indices = np.random.permutation(range(n))[:N] 4 5X = mnist.data[indices] 6y = mnist.target[indices] 7Y = np.eye(10)[y.astype(int)] # 1-of-K 表現に変換
python
1print(X.shape) 2print(y.shape) 3print(Y.shape) 4print(y) 5print(y.astype(int)) 6 7#(30000, 784) 8#(30000,) 9#(30000, 10) 10#[ 3. 2. 8. ..., 5. 9. 2.] 11#[3 2 8 ..., 5 9 2]
最終行についてです。
numpy.eye(n)はn*nの単位行列を作ることはわかりました。
https://docs.scipy.org/doc/numpy-1.12.0/reference/generated/numpy.eye.html
y.astype(int)は行列yをint型に型変換しているのもわかりましたs。
しかし
np.eye(10)[y.astype(int)]は一体何をしているのでしょうか。
[]が指す意味がわかりません。配列の場所(?)の指定でしょうか(x[2]のような)
どなたかよろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。