VOOZH about

URL: https://www.geeksforgeeks.org/python/numpy-delete-python/

⇱ numpy.delete() in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

numpy.delete() in Python

Last Updated : 23 Jan, 2026

The numpy.delete() function returns a new array with the deletion of sub-arrays along with the mentioned axis.


Output
[10 30 40]

Here, the element at index 1 is removed from the array.

Syntax

numpy.delete(array, object, axis = None)

Parameters: 

  • array: [array_like]Input array.
  • object: [int, array of ints]Sub-array to delete
  • axis: Axis along which we want to delete sub-arrays. By default, it object is applied to flattened array

Return: A new NumPy array with the specified elements removed.

Let's look at some of the examples:

Deletion from 1D array 


Output
('Array:', array([0, 1, 2, 3, 4]))
('Shape:', (5,))

Deleting index 2: [0 1 3 4]
('Shape:', (4,))

Deleting indices [1, 2]: [0 3 4]
('Shape:', (3,))

Explanation:

  • np.arange(5) creates a 1D array with values from 0 to 4.
  • np.delete(arr, 2) removes the element at index 2.
  • np.delete(arr, [1, 2]) removes elements at indices 1 and 2.
  • Each call returns a new array with reduced size.

Deletion from a 2D Array

Output:

Array:
[[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]]
Shape: (3, 4)

After deleting row 1:
[[ 0 1 2 3]
[ 8 9 10 11]]
Shape: (2, 4)

After deleting column 1:
[[ 0 2 3]
[ 4 6 7]
[ 8 10 11]]
Shape: (3, 3)

Explanation:

  • reshape(3, 4) converts the array into 3 rows and 4 columns.
  • axis=0 deletes an entire row at index 1.
  • axis=1 deletes an entire column at index 1.
  • The shape of the array changes based on the axis used.

Deletion Using a Boolean Mask 


Output
('Original array:', array([0, 1, 2, 3, 4]))
('Mask:', array([False, True, False, True, True]))
('After deletion:', array([1, 3, 4]))

Explanation:

  • mask is a boolean array controlling which elements to keep.
  • False values indicate elements to exclude.
  • Boolean indexing filters the array without using np.delete().
Comment