Python Program to remove an element from a list ( Using NumPy Library)

bookmark

# Python program to remove an element from a list using numpy library  
import numpy as np  
my_list = [1, 2, 3, 4, 5]  
index_to_remove = 2  # Index of element to remove  
my_array = np.array(my_list)  
my_array = np.delete(my_array, index_to_remove)  
my_list = my_array.tolist()  
print(my_list)    


Output:

[1, 2, 4, 5]