[Tutor] about array

linda.s samrobertsmith at gmail.com
Tue Dec 26 07:17:47 CET 2006


When I read the following code, I found it was very hard for me to
understand the meaning of a[1:3,:-1:2]  for a[i,j] for i=1,2 and
j=0,2,4; the same as a[::3,2:-1:2]

>>> a
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.]])
>>> a[1:3,:-1:2]                 # a[i,j] for i=1,2 and j=0,2,4
array([[ 6., 8., 10.],
[ 12., 14., 16.]])
>>> a[::3,2:-1:2]                     # a[i,j] for i=0,3 and j=2,4
array([[ 2., 4.],
[ 20., 22.]])


More information about the Tutor mailing list