VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-remove-specific-elements-from-a-numpy-array/

⇱ How to remove specific elements from a NumPy array ? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to remove specific elements from a NumPy array ?

Last Updated : 23 Jul, 2025

In this article, we will discuss how to remove specific elements from the NumPy Array. 

Remove specific elements from a NumPy 1D array

Deleting element from NumPy array using np.delete()

The delete(array_name ) method will be used to do the same. Where array_name is the name of the array to be deleted and index-value is the index of the element to be deleted. For example, if we have an array with 5 elements, The indexing starts from 0 to n-1. If we want to delete 2, then 2 element index is 1. So, we can specify If we want to delete multiple elements i.e. 1,2,3,4,5 at a time, you can specify all index elements in a list.

Remove a Specific element in a 1D array

Program to create an array with 5 elements and delete the 1st element.

Output:

[1 2 3 4 5]
remaining elements after deleting 1st element [2 3 4 5]

Remove Multiple elements  in a 1D array

Program to create an array with 5 elements and delete the 1st and last element.

Output:

[1 2 3 4 5]
remaining elements after deleting 1st and last element [2 3 4]

Remove a Specific NumPy Array Element by Value in a 1D array

Removing 8 values from an array.

Output:

[1 2 3 4 5 6 7]

Removing multiple elements from a NumPy using an index

Pass an array containing the indexes of all the elements except the index of the element to be deleted, This will delete the element from the array.

Output:

[9 8 7 6 5 3 2 1]

Remove specific elements from a NumPy 2D array

Remove a column in a 2D array

Deleting 1st column.

Output:

[[ 1 3 4]
 [ 5 7 8]
 [ 9 11 12]]

Remove a row in a 2D array

Deleting 1st row.

Output:

[[ 1 2 3 4]
 [ 9 10 11 12]]

Remove Multiple elements  in a 2D array

Removing multiple elements from a 2D array. Here, we are removing 1st and last column from an array.

Output:

[[ 2 3]
 [ 6 7]
 [10 11]]
Comment
Article Tags: