numpy delete method doing strange thing

1

I was testing the delete method of the array class of the numpy library and something strange happened: I delete the index element 0 from the array, but the index element 1 is excluded. I am not understanding what this delete is doing

>>> import numpy as np
>>> lista = np.array([1,2,3,4,5,6])
>>> lista
array([1, 2, 3, 4, 5, 6])
>>> lista[0]
1
>>> lista = np.delete(lista,lista[0])
>>> lista
array([1, 3, 4, 5, 6])
    
asked by anonymous 16.10.2017 / 09:44

1 answer

1

The% num of the numpy library removes a sub-array based on the index and not on the value of the element to remove.

In your example what you want to do is:

lista = np.delete(lista,0) #indice 0 a ser removido
print(lista) #[2 3 4 5 6]

You can even pass a list of indexes to remove by doing:

lista = np.delete(lista,[0,1,3]) #indice 0, 1 e 3 a serem removidos
print(lista) #[3 5 6]

See both examples on Ideone

Documentation for np.delete

    
16.10.2017 / 11:54