Indexing all items excluding an index from the back
Question:
I want to slice a numpy array such that an index, -7 for example, is excluded. What is the best way to do this?
Answers:
What about a double slicing?
a = np.arange(10)*10
# -7
# array([ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90])
idx = -7
np.r_[a[:idx], a[idx+1:]]
Output:
array([ 0, 10, 20, 40, 50, 60, 70, 80, 90])
I want to slice a numpy array such that an index, -7 for example, is excluded. What is the best way to do this?
What about a double slicing?
a = np.arange(10)*10
# -7
# array([ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90])
idx = -7
np.r_[a[:idx], a[idx+1:]]
Output:
array([ 0, 10, 20, 40, 50, 60, 70, 80, 90])