Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 266
Framester Avatar asked Aug 19 '11 15:08

Framester


People also ask

What is :: double colon in python?

it means 'nothing for the first argument, nothing for the second, and jump by three'. It gets every third item of the sequence sliced.

What does double colon mean in NumPy?

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).

What does :: mean in NumPy array?

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.]])

What does colon mean in NumPy?

A colon on the right side of an index means everything after the specified index.


1 Answers

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] 
like image 81
GWW Avatar answered Sep 22 '22 06:09

GWW