numpy.delete() function with example in python

Spread the love

numpy.delete(): This function return a new array with sub-arrays along an axis deleted. For a one dimensional array, this returns those entries not returned by arr[obj].

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

arr : array_like
Input array.

obj : slice, int or array of ints
Indicate which sub-arrays to remove.

axis : int, optional
The axis along which to delete the subarray defined by obj. If axis is None, obj is applied to the flattened array.

out : ndarray
A copy of arr with the elements specified by obj removed. Note that delete does not occur in-place. If axis is None, out is a flattened array.

import numpy as np a = np.array([[1,2,3,4],[5,6,7,8]]) b= np.delete(a,0,1) print(b) c= np.delete(a,1,1) print(c)


[[2 3 4]
[6 7 8]]
[[1 3 4]
[5 7 8]]


Leave a Reply

Your email address will not be published. Required fields are marked *