P.J - 9 months ago 56

Python Question

when calling the "np.delete()", I am not interested to define a new variable for the reduced size array. I want to execute the delete on the original numpy array. Any thought?

`>>> arr = np.array([[1,2], [5,6], [9,10]])`

>>> arr

array([[ 1, 2],

[ 5, 6],

[ 9, 10]])

>>> np.delete(arr, 1, 0)

array([[ 1, 2],

[ 9, 10]])

>>> arr

array([[ 1, 2],

[ 5, 6],

[ 9, 10]])

but I want:

>>> arr

array([[ 1, 2],

[ 9, 10]])

Answer Source

NumPy arrays are fixed-size, so there can't be an in-place version of `np.delete`

. Any such function would have to change the array's size.

The closest you can get is reassigning the `arr`

variable:

```
arr = numpy.delete(arr, 1, 0)
```