There are several ways to delete rows from NumPy array.

The easiest one is to use basic indexing as with standard Python lists:

>>> import numpy as np
>>> x = np.arange(35).reshape(7, 5)
>>> x
array([[ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14],
       [15, 16, 17, 18, 19],
       [20, 21, 22, 23, 24],
       [25, 26, 27, 28, 29],
       [30, 31, 32, 33, 34]])
>>> result = x[5:]
>>> result
array([[25, 26, 27, 28, 29],
       [30, 31, 32, 33, 34]])

You can select not only rows but columns as well:

>>> x[:2, 1:4]
array([[1, 2, 3],
       [6, 7, 8]])

Another way is to use "fancy indexing" (indexing arrays using arrays):

>>> x[[0, 2, 6]]
array([[ 0,  1,  2,  3,  4],
       [10, 11, 12, 13, 14],
       [30, 31, 32, 33, 34]])

You can achieve the same using np.take:

>>> np.take(x, [0, 2, 6], axis=0)
array([[ 0,  1,  2,  3,  4],
       [10, 11, 12, 13, 14],
       [30, 31, 32, 33, 34]])

Yet another option is to use np.delete as in the question. For selecting the rows/columns for deletion it can accept slice objects, int, or array of ints:

>>> np.delete(x, slice(0, 5), axis=0)
array([[25, 26, 27, 28, 29],
       [30, 31, 32, 33, 34]])
>>> np.delete(x, [0, 2, 3], axis=0)
array([[ 5,  6,  7,  8,  9],
       [20, 21, 22, 23, 24],
       [25, 26, 27, 28, 29],
       [30, 31, 32, 33, 34]])

But all this time that I've been using NumPy I never needed this np.delete, as in this case it's much more convenient to use boolean indexing.

As an example, if I would want to remove/select those rows that start with a value greater than 12, I would do:

>>> mask_array = x[:, 0] < 12  # comparing values of the first column
>>> mask_array
array([ True,  True,  True, False, False, False, False])
>>> x[mask_array]
array([[ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14]])
>>> x[~mask_array]  # ~ is an element-wise inversion
array([[15, 16, 17, 18, 19],
       [20, 21, 22, 23, 24],
       [25, 26, 27, 28, 29],
       [30, 31, 32, 33, 34]])

For more information refer to the documentation on indexing: https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html

Answer from Georgy on Stack Overflow
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: Delete rows/columns from an array with np.delete() | note.nkmk.me
February 5, 2024 - ... Users must specify the target axis (dimension) and the positions (such as row or column numbers) to be deleted. Additionally, it is possible to delete multiple rows or columns simultaneously using a list or a slice.
Top answer
1 of 3
25

There are several ways to delete rows from NumPy array.

The easiest one is to use basic indexing as with standard Python lists:

>>> import numpy as np
>>> x = np.arange(35).reshape(7, 5)
>>> x
array([[ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14],
       [15, 16, 17, 18, 19],
       [20, 21, 22, 23, 24],
       [25, 26, 27, 28, 29],
       [30, 31, 32, 33, 34]])
>>> result = x[5:]
>>> result
array([[25, 26, 27, 28, 29],
       [30, 31, 32, 33, 34]])

You can select not only rows but columns as well:

>>> x[:2, 1:4]
array([[1, 2, 3],
       [6, 7, 8]])

Another way is to use "fancy indexing" (indexing arrays using arrays):

>>> x[[0, 2, 6]]
array([[ 0,  1,  2,  3,  4],
       [10, 11, 12, 13, 14],
       [30, 31, 32, 33, 34]])

You can achieve the same using np.take:

>>> np.take(x, [0, 2, 6], axis=0)
array([[ 0,  1,  2,  3,  4],
       [10, 11, 12, 13, 14],
       [30, 31, 32, 33, 34]])

Yet another option is to use np.delete as in the question. For selecting the rows/columns for deletion it can accept slice objects, int, or array of ints:

>>> np.delete(x, slice(0, 5), axis=0)
array([[25, 26, 27, 28, 29],
       [30, 31, 32, 33, 34]])
>>> np.delete(x, [0, 2, 3], axis=0)
array([[ 5,  6,  7,  8,  9],
       [20, 21, 22, 23, 24],
       [25, 26, 27, 28, 29],
       [30, 31, 32, 33, 34]])

But all this time that I've been using NumPy I never needed this np.delete, as in this case it's much more convenient to use boolean indexing.

As an example, if I would want to remove/select those rows that start with a value greater than 12, I would do:

>>> mask_array = x[:, 0] < 12  # comparing values of the first column
>>> mask_array
array([ True,  True,  True, False, False, False, False])
>>> x[mask_array]
array([[ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14]])
>>> x[~mask_array]  # ~ is an element-wise inversion
array([[15, 16, 17, 18, 19],
       [20, 21, 22, 23, 24],
       [25, 26, 27, 28, 29],
       [30, 31, 32, 33, 34]])

For more information refer to the documentation on indexing: https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html

2 of 3
8

If you want to delete selected rows you can write like

np.delete(x, (1,2,5), axis = 0)

This will delete 1,2 and 5 th line, and if you want to delete like (1:5) try this one

np.delete(x, np.s_[0:5], axis = 0)

by this you can delete 0 to 4 lines from your array.

np.s_[0:5] --->> slice(0, 5, None) both are same.

Discussions

python - deleting rows in numpy array - Stack Overflow
So you could find the indices of the rows which have a 0 in them, put them in a list or a tuple and pass this as the second argument of the function. ... Thanks! I had the same problem, and I could not figure out why simply calling numpy.delete(x, index) didn't work. More on stackoverflow.com
🌐 stackoverflow.com
Faster way to delete numpy array rows than numpy.delete?
Why delete them at all? Just index your array. a[a.any(axis=1)] Breakdown: In [204]: a Out[204]: array([[1, 2], [0, 0], [1, 0], [5, 5], [0, 0]]) In [205]: a.any(axis=1) # checks if there are ANY nonzero values on each row Out[205]: array([ True, False, True, True, False], dtype=bool) In [206]: a[a.any(axis=1)] Out[206]: array([[1, 2], [1, 0], [5, 5]]) Deleting rows one by one means removing that element from the array, and going to each subsequent element and shifting it down one in the array. For each single delete. Instead, if you just boolean index, then you're creating just a view of the data which you can assign to a new array so you don't have to one by one shift the whole array a bunch of times. More on reddit.com
🌐 r/learnpython
5
3
December 19, 2018
python - Numpy delete multiple rows matching criteria - Stack Overflow
The 6th column 'PercentCnt' which can be accessed by name 'PercentCnt' contains numbers from 0 to 50 the 7th column 'ModelType' contains numbers from 0 to 5 so i need to remove or delete array rows which match these criteria 'PercentCnt'<50 and 'ModelType'<2. More on stackoverflow.com
🌐 stackoverflow.com
Python - NumPy - deleting multiple rows and columns from an array - Stack Overflow
For your second example, you want to select rows 0 and 1 and columns 0 and 1, which can be done using basic slicing: ... Sign up to request clarification or add additional context in comments. ... numpy.ix was exactly what I was after. I should sit down and read the numpy documentation one day. More on stackoverflow.com
🌐 stackoverflow.com
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-delete-multiple-rows-of-numpy-array
How to delete multiple rows of NumPy array ? - GeeksforGeeks
July 23, 2025 - 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().
🌐
Tutorialsinhand
tutorialsinhand.com › https://tutorialsinhand.com › articles › how-to-delete-rows-from-a-numpy-array
delete a row from a numpy array | delete multiple rows in numpy array
June 17, 2022 - Scenario -2 : Remove multiple rows using delete() method · Here we are going to use delete() method, which is available in numpy module to delete multiple rows in numpy array by specifying index positions in a list.
🌐
Medium
medium.com › @heyamit10 › numpy-delete-in-numpy-90ffd785a5cf
Understanding numpy.delete() with Syntax and Parameters | by Hey Amit | Medium
February 8, 2025 - Remember, always double-check your indices before calling numpy.delete(). ... Absolutely! Just pass a list of indices to the obj parameter. This is perfect for cleaning up datasets with multiple unwanted values.
Find elsewhere
🌐
Iditect
iditect.com › programming › python-example › how-to-delete-multiple-rows-of-numpy-array.html
How to delete multiple rows of NumPy array?
In NumPy, you can delete multiple rows from an array using the numpy.delete() function. You would specify the array, the indices of the rows you want to delete, and the axis along which to perform the deletion.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-remove-rows-from-a-numpy-array-based-on-multiple-conditions
How to remove rows from a Numpy array based on multiple conditions ? | GeeksforGeeks
July 3, 2021 - For doing our task, we will need some inbuilt methods provided by the NumPy module which are as follows: np.delete(ndarray, index, axis): Delete items of rows or columns from the NumPy array based on given index conditions and axis specified, ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › delete-rows-and-columns-of-numpy-ndarray
Delete rows and columns of NumPy ndarray - GeeksforGeeks
April 21, 2021 - In this article, we will discuss how to delete the specified rows and columns in an n-dimensional array. We are going to delete the rows and columns using numpy.delete() method.
🌐
Delft Stack
delftstack.com › home › howto › numpy › python numpy delete row
How to Delete Row in NumPy | Delft Stack
March 14, 2025 - Yes, you can delete multiple rows by passing a list of indices to the numpy.delete() function.
🌐
thisPointer
thispointer.com › home › numpy › np.delete(): remove items/rows/columns from numpy array
np.delete(): Remove items/rows/columns from Numpy Array - thisPointer
May 11, 2023 - It returned a copy of the passed ... multiple elements from a numpy array by index positions, pass the numpy array and list of index positions to be deleted to np.delete() i.e....
🌐
Skytowner
skytowner.com › explore › numpy_delete_method
NumPy | delete method with Examples
ParametersReturn valueExamplesDeleting ... data science with 100+ top-tier guides Start your free 7-days trial now! Numpy's delete(~) method returns a new Numpy array with the specified values deleted....
🌐
IncludeHelp
includehelp.com › python › how-to-delete-a-batch-of-rows-of-a-numpy-array-simultaneously.aspx
Python - How to delete a batch of rows of a NumPy array simultaneously?
October 8, 2023 - # Import numpy import numpy as np # Import pandas import pandas as pd # Creating a numpy array arr = np.arange(20).reshape(10,2, order='F') # Display original array print("Original array:\n",arr,"\n") # Defining a list of indices for specific rows ind = [2,7] # Deleting the rows res = np.delete(arr, ind , axis=0) # Display result print("Result:\n",res,"\n")
🌐
Vultr Docs
docs.vultr.com › python › third party › numpy › delete()
Python Numpy delete() - Remove Elements
November 6, 2024 - Specify multiple indices in a list format that need to be deleted. Execute the numpy.delete() function with these indices. ... Here, elements at indices 1, 3, 5—corresponding to 1, 3, 5 respectively—are deleted from array_md.
🌐
Stack Overflow
stackoverflow.com › questions › 57143330 › delete-multiple-rows-at-once-in-python
numpy - delete multiple rows at once in python - Stack Overflow
July 22, 2019 - import numpy as np matrice=[[2,3,5,6,8],[7,8,9,6,5],[5,8,8,8,9],[5,5,4,8,9]] a = range(3) matrice = np.delete(matrice, a, axis=0) print(matrice) Other problems with your code: You did not close the list for matrice ... For selecting the rows/columns for deletion np.delete can accept slice objects, int, or array of ints.
🌐
Iditect
iditect.com › faq › python › deleting-rows-in-numpy-array.html
Deleting rows in numpy array
You can delete rows from a NumPy array using the numpy.delete() function or by indexing.