0

Say if I have an array:

a = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

I want to create a new array which takes a and an increment, and creates a new array, for eg: If I want increments of 2, then my new array would look like: [1, 3, 5, 7, 9]

or if I want increments of 3, then: [1, 4, 7, 10]

Is there any functions in numpy or python in general which allows me to do this? Instead of having to create a for loop which iterates through and creates a new array?

anony
  • 79
  • 1
  • 2
  • 10

1 Answers1

0

Use

a[::increment]

For example:

a[::2]

array([1, 3, 5, 7, 9])

Thomas Schillaci
  • 2,348
  • 1
  • 7
  • 19