0

I want to delete an element from a numpy array by index.

The commands

arr = np.linspace(-5,5,10)
del arr[0]

The code above throws an error saying cannot delete array elements. Using pop doesn't work either. What should I do?

2
  • It's not an exact duplicate because this one asks about deleting just one element rather than many. But maybe others can look into it and decide. Commented Jun 5, 2019 at 6:21
  • del and pop are python list operations, and don't apply to ndarray. Commented Jun 5, 2019 at 7:30

1 Answer 1

1

You should use np.delete for it.

arr = np.linspace(-5,5,10)
arr = np.delete(arr, 0)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.