What is :: (double colon) in numpy like in myarray[0::3]?

Framester picture Framester · Aug 19, 2011 · Viewed 27.9k times · Source

Possible Duplicate:
What is :: (double colon) in Python?

I read the question What is :: (double colon) in Python when subscripting sequences?, but this not answer what myarray[x::y] mean.

Answer

GWW picture GWW · Aug 19, 2011

It prints every yth element from the list / array

>>> a = [1,2,3,4,5,6,7,8,9]
>>> a[::3]
[1, 4, 7]

The additional syntax of a[x::y] means get every yth element starting at position x

ie.

>>> a[2::3]
[3, 6, 9]