0
In [136]: d = np.ones((1,2,3,4))
In [167]: d[0][0][0:2][0]
Out[167]: array([ 1., 1., 1., 1.])
を返す、なぜそれが正確に2つの要素[0] [0:2] [0]上記のように[0]ない二つの要素
In [136]: d = np.ones((1,2,3,4))
In [167]: d[0][0][0:2][0]
Out[167]: array([ 1., 1., 1., 1.])
を返す、なぜそれが正確に2つの要素[0] [0:2] [0]上記のように[0]ない二つの要素
ルックを返すていません配列そのもの。それは自明でなければなりません。
>>> d
array([[[[ 1., 1., 1., 1.],
[ 1., 1., 1., 1.],
[ 1., 1., 1., 1.]],
[[ 1., 1., 1., 1.],
[ 1., 1., 1., 1.],
[ 1., 1., 1., 1.]]]])
# first you grab the first and only element
>>> d[0]
array([[[ 1., 1., 1., 1.],
[ 1., 1., 1., 1.],
[ 1., 1., 1., 1.]],
[[ 1., 1., 1., 1.],
[ 1., 1., 1., 1.],
[ 1., 1., 1., 1.]]])
# then you get the first element out of the two groups
>>> d[0][0]
array([[ 1., 1., 1., 1.],
[ 1., 1., 1., 1.],
[ 1., 1., 1., 1.]])
# thirdly, you get the two first elements as a list
>>> d[0][0][0:2]
array([[ 1., 1., 1., 1.],
[ 1., 1., 1., 1.]])
# finally, you get the first element of the list
>>> d[0][0][0:2][0]
array([ 1., 1., 1., 1.])
私は愚かになります。私は欲しいものがd [0,0,0:2,0]であることを知ります。ありがとう! – NormanOu
ああ、私は今あなたが望むものを見る...スライスの詳細:https://docs.python.org/2.3/whatsnew/section-slices.html – mk2
また、1秒ではなくこの配列構成を使用することもできます。 .. d = np.arange(1 * 2 * 3 * 4).reshape(1,2,3,4)...あなたが戻ってきたものを見るのが簡単になります。 – NaN