Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

NumPy · Function

np.delete

Returns a new array with selected elements or sub-arrays removed. Use axis to control the dimension, or leave it as None to delete from the flattened input.

How it works

np.delete returns a new array after removing the positions selected by obj. With axis specified, it removes sub-arrays along that dimension; with axis=None, it first treats the input as flattened and returns a one-dimensional result.

Syntax

numpy.delete(arr, obj, axis=None)

Parameters

NameTypeDescription
arrarray_likeInput array.
objslice, int, array-like of ints or boolsIndices or sub-arrays to remove along the specified axis.
axisint, optionalAxis along which to delete the subarray specified by obj. If None, obj applies to the flattened array.

Returns

out ndarray: A copy of arr with the elements specified by obj removed.

Key points

  • The operation constructs and returns a new array with selected sub-arrays removed.
  • For one-dimensional input, deletion keeps the entries that are outside the selection made by arr[obj].
  • obj identifies which indices or sub-arrays should be removed on the selected axis.
  • axis determines the dimension along which deletion occurs.
  • An axis of None makes NumPy apply obj to a flattened view of the input.
  • The return value is a copy of arr with the requested elements removed.

Common mistakes

  • The function does not modify the input array; assign its returned copy if the change should be retained.
  • Omitting axis changes the operation to the flattened array, so multidimensional structure is not preserved.

Example: Remove one column

import numpy as np

arr = np.array([[1, 2, 3], [4, 5, 6]])
result = np.delete(arr, 1, axis=1)
print(result)
# [[1 3]
#  [4 6]]

Creates a new array after removing column 1; the input remains unchanged.

When to use it

Edit multidimensional data

Remove selected columns or rows from a matrix while preserving the other dimension.

Filter positional entries

Drop individual entries or ranges from a one-dimensional array.

Apply index selections

Delete positions selected by integer indices or a boolean mask.

Interview questions

QWhat does np.delete do?

It returns a new array with the selected elements or sub-arrays removed, rather than editing arr in place. For a one-dimensional input, the result contains entries not selected by arr[obj].

Follow-up: What happens when axis is omitted? obj is applied after flattening the input, and the returned result is one-dimensional.

QWhat forms can obj take?

obj may be a slice, an integer, an integer array, or a boolean array. These identify the indices or positions to remove along the chosen axis.

Follow-up: How are boolean arrays interpreted? They act as masks for selecting positions to delete, rather than being converted to integer indices.

QHow does axis affect np.delete?

axis selects the dimension whose sub-arrays are removed. If it is None, NumPy applies obj to the flattened input instead.

Follow-up: Does np.delete mutate the original array? No; it always produces a copy, so the original must be replaced explicitly if desired.

  • numpy.append
  • numpy.insert
  • numpy.place
  • numpy.take

Source: numpy.delete. Checked 2026-10-15.