2

i have an other question, i have this array in Python :

import numpy as np

A = np.zeros((5));
A[0] = 2;
A[1] = 3;
A[2] = 7;
A[3] = 1;
A[4] = 8;

And what I want to do is to delete A[i] for i from 2 to 4 that is to say i am looking for a command like this :

A = np.delete(A, [2:4]) but unfortunately it doesn't work because I saw the documentation here : http://docs.scipy.org/doc/numpy/reference/generated/numpy.delete.html but it doesn't help me.

Thank you for your help !

2
  • 2
    np.delete(A, np.s_[2:5]) works well enough for me. Commented Aug 4, 2016 at 15:02
  • Thank you very much ! it works Commented Aug 4, 2016 at 15:13

2 Answers 2

1

If what you want is deleting the positions from numpy array you can use:

np.delete(A, slice(2,5))  # note that the interval is inclusive, exclusive [2, 5)
Sign up to request clarification or add additional context in comments.

Comments

0

What you need to use is actually, numpy.delete, but you need to pass the proper second argument, e.g.:

np.delete(A, slice(2, 4))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.