How to Determine Step of Slicing in NumPy


In this example, we will learn how to determine the step of the slicing by the step value in Python NumPy.

Source Code

import numpy as np

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

# get every other element from index 1 to index 5
print(n[3:8:2])

Output:

[4 6 8]
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Advertisement