For instance if you want to remove the third column from an array of shape (2, 3) :

import numpy as np
a = np.ones((2, 3))
b = np.delete(a, 2, axis=1)

Note that delete does not work in-place, so a is unmodified. If you want to keep working on a do :

a = np.delete(a, 2, axis=1)

This will assign the new array to the same variable.

Answer from Nicolas Barbey on Stack Overflow
🌐
GitHub
github.com › numpy › numpy › issues › 15529
numpy.delete is not working · Issue #15529 · numpy/numpy
February 6, 2020 - Reproducing code example: import numpy as np x = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]]) print(x) np.delete(x, 1, axis=1) print(x) [[ 1 2 3 4] [ 5 6 7...
Author: numpy
Discussions

Problems with numpy.delete()
Hi, I am currently experiencing some issues with numpy.delete function. I have got some code which outputs a 3x3 array (from the cv2.Rodrigues function). I then call np.delete(arr, 2, 1) to get rid of the last column in the array. Howeve... More on github.com
🌐 github.com
5
April 17, 2016
debugging - Numpy: np.delete is not removing values in the array - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I am using Python 3.5 with numpy version 1.11.3 and I am facing a really weird issue that might be difficult to reproduce. I loaded a Numpy array arr1 from a pd.DataFrame and np.delete does not seem ... More on stackoverflow.com
🌐 stackoverflow.com
python - Numpy.delete() function not properly deleting element at index - Stack Overflow
I'm facing a simple problem where I have to delete elements from a 2-dimensional NumPy array-like m. When I try to remove an element at a certain index with delete() function, it just doesn't perfo... More on stackoverflow.com
🌐 stackoverflow.com
problems with numpy.delete
In [124]: np.delete(np.arange(0, 100, 1.0), np.arange(1, 100, 1.0)) Out[124]: array([ 0.]) not sure if this is intended behavior, but probably worth looking into! More on github.com
🌐 github.com
10
January 8, 2015
🌐
Reddit
reddit.com › r/learnpython › usage of np.delete
r/learnpython on Reddit: usage of np.delete
April 29, 2021 -

Hey lads n gals

I am working on an assignment, where we are doing a grading system for students on the -3 to 12 scale...

here is the code so far:

import numpy as np

from RoundGrade import roundGrade

def computeFinalGrade(grades):

if -3 in grades:

return -3

if len(grades)==1:

return grades[0]

if len(grades)>=2:

grademin=grades.delete(min(grades))

average=np.mean(grademin)

return roundGrade(average)

grades=np.array([6,9,2,5,2])

print(computeFinalGrade(grades))

however this gives me the error messege:

'numpy.ndarray' object has no attribute 'delete'

i have tried converting the array to a list, but it doesn't help

thanks <3

🌐
GitHub
github.com › numpy › numpy › issues › 7555
Problems with numpy.delete() · Issue #7555 · numpy/numpy
April 17, 2016 - I then call np.delete(arr, 2, 1) to get rid of the last column in the array. However it outputs "IndexError: index 2 is out of bounds for axis 1 with size 1". When I make a new Python script, and type the array out as (i.e.) arr = np.array([a,b,c],[d,e,f],[g,h,i]]), and call the exact same function it works.
Author: numpy
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.delete.html
numpy.delete — NumPy v2.5 Manual
Note that delete does not occur in-place. If axis is None, out is a flattened array. See also · insert · Insert elements into an array. append · Append elements at the end of an array. Notes · Often it is preferable to use a boolean mask. For example: >>> arr = np.arange(12) + 1 >>> mask = np.ones(len(arr), dtype=np.bool) >>> mask[[0,2,4]] = False >>> result = arr[mask,...] Is equivalent to np.delete(arr, [0,2,4], axis=0), but allows further use of mask.
🌐
GitHub
github.com › numpy › numpy › issues › 5434
problems with numpy.delete · Issue #5434 · numpy/numpy
January 8, 2015 - problems with numpy.delete#5434 · Copy link · tychung84 · opened · on Jan 8, 2015 · Issue body actions · Just noticed this: In [122]: np.delete(np.arange(1, 100, 1.0), np.arange(1, 100, 1.0)) Out[122]: array([ 1.]) In [123]: np.delete(np.arange(1, 100, 1.0), np.arange(0, 100, 1.0)) Out[123]: array([], dtype=float64) In [124]: np.delete(np.arange(0, 100, 1.0), np.arange(1, 100, 1.0)) Out[124]: array([ 0.]) not sure if this is intended behavior, but probably worth looking into!
Author: numpy
Find elsewhere
🌐
DataCamp
datacamp.com › doc › numpy › delete-numpy
NumPy delete()
If `axis` is `None`, the array is flattened before deletion. Note: The `obj` parameter can be an integer, a list of integers, or a slice object. The `np.delete()` function does not operate in-place; it returns a new array and leaves the original array unmodified.
🌐
GitHub
github.com › numpy › numpy › issues › 18412
numpy delete where is giving wrong result i.e. always deleting the first element if there is atleast one True · Issue #18412 · numpy/numpy
February 14, 2021 - xyz =np.array( [[[612. , 0.8679449]], [[612. , 0.7679449]], [[206., 0.338741 ]], [[62., 2.338741 ]]]) xyx = np.copy(xyz) np.delete(xyx, np.where([[False], [False],[False],[ False]]), axis=0) but this works fine as output below.
Author: numpy
🌐
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 - a = np.arange(12).reshape(3, 4) ... indexes corresponding to True being deleted. An error occurs if the specified number of elements does not match the size of the dimension....
🌐
Medium
medium.com › @heyamit10 › numpy-delete-in-numpy-90ffd785a5cf
Understanding numpy.delete() with Syntax and Parameters | by Hey Amit | Medium
February 8, 2025 - # A 2D array representing your dataset arr_2d = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) # Delete the second row (index 1) new_arr = np.delete(arr_2d, 1, axis=0) print(new_arr) # Output: # [[1 2 3] # [7 8 9]] # Delete the third column (index 2) new_arr = np.delete(arr_2d, 2, axis=1) print(new_arr) # Output: # [[1 2] # [4 5] # [7 8]] Key points to remember: axis=0: Deletes rows. axis=1: Deletes columns. You might be wondering, “Why not just use slicing?” While slicing works for continuous ranges, numpy.delete() shines when you need precision or to remove non-contiguous elements.
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.delete.html
numpy.delete — NumPy v2.6.dev0 Manual
Note that delete does not occur in-place. If axis is None, out is a flattened array. See also · insert · Insert elements into an array. append · Append elements at the end of an array. Notes · Often it is preferable to use a boolean mask. For example: >>> arr = np.arange(12) + 1 >>> mask = np.ones(len(arr), dtype=np.bool) >>> mask[[0,2,4]] = False >>> result = arr[mask,...] Is equivalent to np.delete(arr, [0,2,4], axis=0), but allows further use of mask.
🌐
w3resource
w3resource.com › numpy › manipulation › delete.php
NumPy: numpy.delete() function - w3resource
April 25, 2026 - Note that delete does not occur in-place. If axis is None, out is a flattened array. Example: Title: Deleting a row from a numpy array using numpy.delete() >>> import numpy as np >>> arr = np.array([[0,1,2], [4,5,6], [7,8,9]]) >>> arr array([[0, 1, 2], [4, 5, 6], [7, 8, 9]]) >>> np.delete(arr, 1, 0) array([[0, 1, 2], [7, 8, 9]])
🌐
Numba Discussion
numba.discourse.group › t › np-delete-unexpected-behaviour-in-an-njit-funcion › 388
Np.delete unexpected behaviour in an njit funcion - Numba - Numba Discussion
December 9, 2020 - Amazing job with the numba version ... njiting @njit def fii(arr, val): return np.delete(arr, np.where(arr==val)) fii(a, -3) The point is that with arr (input arr) is a 1D array; njited fii() only works if np.where does not return the tuple ([whatever indexes],) '''this works:''' ...
🌐
Reddit
reddit.com › r › learnpython › comments › 27zf9v › numpy_delete_not_properly_deleting_the_right
r/learnpython - Numpy delete not properly deleting the right amount?
June 13, 2014 -

I am trying to graph 2 sets of data, radio loud and radio quiet quasars, with radio loud quasars being blue and radio quiet quasars being red. Numpy delete has worked to delete all the indices I've intended except when I try sorting radio loud quasar data from radio quiet. Segment of my code giving me issues:

radians = 0.0174532925
dist = 130658597000000000000000

values = radioflux[0:166583]
searchval = 0
searchvalquietloud = 1


indices = np.where(values == searchval)[0]
radiocut = np.delete(radioflux[0:166583],indices)

quiet = np.where(values <= searchvalquietloud)[0]
radioloud = np.delete(radiocut[0:12464],quiet)

loud = np.where(values > searchvalquietloud)[0]
radioquiet = np.delete(radiocut[0:12464],loud)

distance = np.multiply(redshift,dist)
angle = np.multiply(ra,radians)

distancecut = np.delete(distance,indices)
anglecut = np.delete(angle,indices)

distancequiet = np.delete(distancecut,radioloud)
distanceloud = np.delete(distancecut,radioquiet)

anglequiet = np.delete(anglecut,radioloud)
angleloud = np.delete(anglecut,radioquiet)

The number of items in each array is:

  • Radio Flux: 166583

  • Radio Cut: 12464

  • Radio Loud: 239

  • Radio Quiet: 12225

  • Distance Cut: 12464

  • Angle Cut: 12464

  • Distance Loud: 12120

  • Distance Quiet: 12424

  • Angle Loud: 12120

  • Angle Quiet: 12424

Everything is how it should be except the last four. They should be:

  • Distance Loud: 239

  • Distance Quiet: 12225

  • Angle Loud: 239

  • Angle Quiet: 12225

What is wrong with my code?

Thanks for all your help!

Top answer
1 of 2
2

To me, it appears that you are simply trying to delete an index that is out of the array; hence the lack of change ... From your code len(scale) gives only 17 .

For the record as the doc indicates, numpy.delete(arr,obj) will try to delete the element returned by arr[obj] for a 1-D array so :

  • numpy.delete(arr,0)
  • numpy.delete(arr,[0])
  • numpy.delete(arr,0.0)
  • numpy.delete(arr,[0.0])

will all delete arr[0] which is the zero-th element of that 1-D array.

2 of 2
0

first, delete does not operate in place:

In [849]: a=np.arange(10)
In [850]: np.delete(a,[1])
Out[850]: array([0, 2, 3, 4, 5, 6, 7, 8, 9])  # returned array
In [851]: a
Out[851]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])  # not change in a

If I do an out of bounds delete with a scalar, I get an error:

In [853]: a1=np.delete(a,11)
...
IndexError: index 11 is out of bounds for axis 0 with size 10

But if the delete is a list, it appears the bounds check does not operate (is there a parameter for that?)

In [854]: a1=np.delete(a,[11])
In [855]: a1
Out[855]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

a1 is a copy though; changing one of its values does not affect a.

In [858]: a1[-1]=100
In [859]: a1
Out[859]: array([  0,   1,   2,   3,   4,   5,   6,   7,   8, 100])
In [860]: a
Out[860]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

np.delete is a complicated Python function, written to be quite general. It can be studied. It is not a fundamental function. It is not doing anything you can't do just as well with basic array operations like masking, indexing and/or selective copying. And it isn't going to be faster.

================

You can study np.delete. My memory is that it often does the following:

delete via mask for scalar:

In [863]: mask=np.ones(a.shape,dtype=bool)
In [864]: mask[1]=False
In [865]: a[mask]
Out[865]: array([0, 2, 3, 4, 5, 6, 7, 8, 9])

for list:

In [866]: mask=np.ones(a.shape,dtype=bool)
In [867]: mask[[1,3,5]]=False
In [868]: a[mask]
Out[868]: array([0, 2, 4, 6, 7, 8, 9])

==================

Recreation of your script with added displays:

In [874]: scale=[1,2]
In [875]: for h in range(500,3001,500):scale.append(h)
In [876]: len(scale)
Out[876]: 8
In [877]: scale+=[4000,5000]
In [878]: for h in range(7000,17001,2000):scale.append(h)
In [879]: len(scale)
Out[879]: 16
In [880]: scale.append(1000)
In [881]: Scale=np.array(scale)
In [882]: Scale.shape
Out[882]: (17,)
In [883]: np.delete(Scale,[1000])
Out[883]: 
array([    1,     2,   500,  1000,  1500,  2000,  2500,  3000,  4000,
        5000,  7000,  9000, 11000, 13000, 15000, 17000,  1000])

So there are only 17 items in the array, not a 1000. And as I illustrated with a delete list, it does not raise an error if it is out of bounds. Hence the delete result is a copy of the input.

By the way I create that same array with an array concatenate

In [886]: np.r_[1, 2, 500:3001:500, [4000,5000], 7000:17001:2000, 1000]
Out[886]: 
array([    1,     2,   500,  1000,  1500,  2000,  2500,  3000,  4000,
        5000,  7000,  9000, 11000, 13000, 15000, 17000,  1000])

Even sticking with the list I can avoid the loops with extend:

In [887]: scale=[1,2]
In [888]: scale.extend(range(500,3001,500))
In [889]: scale.extend([4000,5000])
In [890]: scale.extend(range(7000,17001,2000))
In [891]: scale.append(1000)