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?

Asked By: PeriodicParticle

||

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])
Answered By: mozway
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.