Deleting Elements from an array

Numpy arrays have a fixed size, hence you cannot simply delete an element from them. The simplest way to achieve what you want is to use slicing:

a = a[3:]

This will create a new array starting with the 4th element of the original array.

For certain scenarios, slicing is just not enough. If you want to create a subarray consisting of specific elements from the original array, you can use another array to select the indices:

>>> a = arange(10, 20)
>>> a[[1, 4, 5]]
array([11, 14, 15])

So basically, a[[1,4,5]] will return an array that consists of the elements 1,4 and 5 of the original array.


It works for me:

import numpy as np
a = np.delete(a, k)

where "a" is your numpy arrays and k is the index position you want delete.

Hope it helps.

Tags:

Python

Numpy