How to Negative Slice a NumPy Array Given a Start and End Index


In this example we will show how to negative slice a NumPy array given a start and end index in Python.

Source Code

import numpy as np

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

# slice from the index 8 from the end to index 3 (not included) from the end
print(n[-8:-3])

Output:

[3 4 5 6 7]
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments