VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-delete-multiple-rows-of-numpy-array/

⇱ How to delete multiple rows of NumPy array ? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to delete multiple rows of NumPy array ?

Last Updated : 23 Jul, 2025

NumPy is the Python library that is used for working with arrays. In Python there are lists which serve the purpose of arrays but they are slow. Therefore, NumPy is there to provide us with the array object that is much faster than the traditional Python lists. The reason for them being faster is that they store arrays at one continuous place in memory, unlike lists which makes the process accessing and manipulation much more efficient.

There are a number of ways to delete multiple rows in NumPy array. They are given below :-

  • numpy.delete() - The numpy.delete() is a function in Python which returns a new array with the deletion of sub-arrays along with the mentioned axis. By keeping the value of the axis as zero, there are two possible ways to delete multiple rows using numpy.delete().
     

Using arrays of ints, Syntax: np.delete(x, [ 0, 2, 3], axis=0)

Output:

[[15 16 17 18 19] 
[20 21 22 23 24] 
[25 26 27 28 29] 
[30 31 32 33 34]]

Using slice objects – The slice() function allows us to specify how to slice a sequence. 

Syntax of slice function: slice(start, stop, step index)

Output: 

[[15 16 17 18 19]
 [20 21 22 23 24]
 [25 26 27 28 29]
 [30 31 32 33 34]] 
  • Basic Indexing – This is one of the easiest ways to delete multiple rows of NumPy array.
    Syntax for basic indexing: array object(start:stop:step)
     

Output:

[[20 21 22 23 24] 
[25 26 27 28 29] 
[30 31 32 33 34]] 
  • Fancy Indexing – This is the method in which we index the arrays using arrays allowing us to access multiple array elements at once by referring to their index number.
    Syntax: array object[row numbers] 

Output:

[[ 0 1 2 3 4] 
[ 5 6 7 8 9] 
[10 11 12 13 14]]
  • numpy.take() – The numpy.take() is a function in python which is used to return elements from arrays along the mentioned axis and indices. Now, if one mentions the value of axis as null/zero, then it is able to provide us with the desired indices and work in a way similar to Fancy Indexing.

Output:

[[ 0 1 2 3 4] 
[10 11 12 13 14] 
[30 31 32 33 34]] 
  • Boolean Indexing – This is a very convenient method, specially when we put some condition for the deletion.
    For example, we want to remove the rows that start with a value greater than 10. Then we can do it by using Boolean Indexing. 

Output:

[[0 1 2 3 4]
 [5 6 7 8 9]]
Comment