numpy.delete() in Python (original) (raw)

Last Updated : 23 Jan, 2026

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

Python `

import numpy as np

a = np.array([10, 20, 30, 40]) r = np.delete(a, 1)

print(r)

`

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

Syntax

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

**Parameters:

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

Let's look at some of the examples:

Deletion from 1D array

Python `

import numpy as np

arr = np.arange(5) print("Array:", arr) print("Shape:", arr.shape)

Delete a single element

obj = 2 a = np.delete(arr, obj) print("\nDeleting index {}: {}".format(obj, a)) print("Shape:", a.shape)

Delete multiple elements

obj = [1, 2] b = np.delete(arr, obj) print("\nDeleting indices {}: {}".format(obj, b)) print("Shape:", b.shape)

`

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:

Deletion from a 2D Array

Python `

import numpy as np

arr = np.arange(12).reshape(3, 4) print("Array:\n", arr) print("Shape:", arr.shape)

Delete row at index 1

a = np.delete(arr, 1, axis=0) print("\nAfter deleting row 1:\n", a) print("Shape:", a.shape)

Delete column at index 1

b = np.delete(arr, 1, axis=1) print("\nAfter deleting column 1:\n", b) print("Shape:", b.shape)

`

**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:

Deletion Using a Boolean Mask

Python `

import numpy as np

a = np.arange(5) print("Original array:", a)

mask = np.ones(len(a), dtype=bool) mask[[0, 2]] = False

print("Mask:", mask)

res = a[mask] print("After deletion:", res)

`

Output

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

**Explanation: