How to index an array with even steps?

Akira Li 4kir4.1i at gmail.com
Fri Jul 25 08:02:48 EDT 2014


fl <rxjwg98 at gmail.com> writes:
> In Python, ':' is used to indicate range (while in Matlab I know it can be used
> to control steps). How to index an array with 0, 5, 10, 15...995?

Just use slicing:

  >>> L = range(1000) # your array goes here
  >>> L[::5] 
  [0, 5, 10, 15, ..., 995] # Python 2
  range(0, 1000, 5)        # Python 3


--
Akira




More information about the Python-list mailing list