>>> y = np.arange(35).reshape(5,7)
>>> y[1:5:2,::3]
array([[ 7, 10, 13],
[21, 24, 27]])
What does y[1:5:2,::3]
mean? In detail.
>>> y = np.arange(35).reshape(5,7)
>>> y[1:5:2,::3]
array([[ 7, 10, 13],
[21, 24, 27]])
What does y[1:5:2,::3]
mean? In detail.
You can find the details of Python slicing notation
here.
Your case combines slicing notation with numpy notation : y[1:5:2,::3]
is leans slicing 1:5:2
in 1st dimension, and ::3
in 2nd dimension
# Initial array
[[ 0 1 2 3 4 5 6]
[ 7 8 9 10 11 12 13]
[14 15 16 17 18 19 20]
[21 22 23 24 25 26 27]
[28 29 30 31 32 33 34]]
1:5:2
take from values [1;5[
and one over 2, this, in the first dimension, so it keeps values 1
and 3
(you can say rows)
[[ 7 8 9 10 11 12 13]
[21 22 23 24 25 26 27]]
::3
takes all elements are the 2 first values are not provided, but just one over three, in the second dimension
[ 7 8 9 10 11 12 13] => [ 7 10 13] # one over 3