WX_M
WX_M

Reputation: 488

Remove array index based on numpy array

Suppose I have array1 of shape (69316, 5, 5, 28) and array2 of length 10050. I want to remove elements from array2 for indices 0:len(array1). However, I have tried:

array3 = np.delete(array1, array2, axis=0)

Which throws an error (yes, I am upgrading to Python 3 next week):

/usr/lib/python2.7/site-packages/ipykernel_launcher.py:1: DeprecationWarning: in the future out of bounds indices will raise an error instead of being ignored by `numpy.delete`.

and the result I get is:

(67971, 5, 5, 28)

which I want

(69316 - 10050) = 59266 --> (59266, 5, 5, 28)

Therefore, how do I loop through an array of indices I want to delete, without improper indexing after it has been deleted, keeping only the indices which are not within array2?

Upvotes: 0

Views: 88

Answers (1)

Aditya Mishra
Aditya Mishra

Reputation: 1885

Try this out -

array3 = array1[10050:, :, :, :]

Here, I'm saving only the elements after index 10050, keeping the other dimensions intact.

Upvotes: 1

Related Questions