python
1>>> import numpy as np
2>>> np.zeros(4)
3array([0., 0., 0., 0.])
4>>> np.zeros((1,4))
5array([[0., 0., 0., 0.]])
前者は[0., 0., 0., 0.]、後者は[[0., 0., 0., 0.]]なのでよく見ると微妙に違います。数学的に適当な用語がないので、後者はC言語風に2次元配列とでも呼んでみましょうか。
0番目の要素を取ってみます。
python
1>>> np.zeros(4)[0]
20.0
3>>> np.zeros((1,4))[0]
4array([0., 0., 0., 0.])
やっぱり違います。
追記
こういうときはndimを見ると簡単に確認できます。
python
1>>> np.zeros(4).ndim
21
3>>> np.zeros((1,4)).ndim
42
更に追記
これを見ればわかるかも。
python
1>>> np.zeros((1,4))
2array([[0., 0., 0., 0.]])
3>>> np.zeros((2,4))
4array([[0., 0., 0., 0.],
5 [0., 0., 0., 0.]])
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。