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.
it means 'nothing for the first argument, nothing for the second, and jump by three'. It gets every third item of the sequence sliced.
Answer: The double colon is a special case in Python's extended slicing feature. The extended slicing notation string[start:stop:step] uses three arguments start , stop , and step to carve out a subsequence. It accesses every step -th element between indices start (included) and stop (excluded).
The [:, :] stands for everything from the beginning to the end just like for lists. The difference is that the first : stands for first and the second : for the second dimension. a = numpy. zeros((3, 3)) In [132]: a Out[132]: array([[ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.]])
A colon on the right side of an index means everything after the specified index.
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With