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?

Tanmay Bhore
  • 89
  • 2
  • 9
  • 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. – T Tse Jun 05 '19 at 06:21
  • del and pop are python list operations, and don't apply to `ndarray`. – hpaulj Jun 05 '19 at 07:30

1 Answers1

1

You should use np.delete for it.

arr = np.linspace(-5,5,10)
arr = np.delete(arr, 0)
T Tse
  • 786
  • 7
  • 19