MCPcopy Index your code
hub / github.com/numpy/numpy / delete

Function delete

numpy/lib/_function_base_impl.py:5221–5397  ·  view source on GitHub ↗

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]`. Parameters ---------- arr : array_like Input array. obj : slice, int, array-like of ints or bools Indicate indic

(arr, obj, axis=None)

Source from the content-addressed store, hash-verified

5219
5220@array_function_dispatch(_delete_dispatcher)
5221def delete(arr, obj, axis=None):
5222 """
5223 Return a new array with sub-arrays along an axis deleted. For a one
5224 dimensional array, this returns those entries not returned by
5225 `arr[obj]`.
5226
5227 Parameters
5228 ----------
5229 arr : array_like
5230 Input array.
5231 obj : slice, int, array-like of ints or bools
5232 Indicate indices of sub-arrays to remove along the specified axis.
5233
5234 .. versionchanged:: 1.19.0
5235 Boolean indices are now treated as a mask of elements to remove,
5236 rather than being cast to the integers 0 and 1.
5237
5238 axis : int, optional
5239 The axis along which to delete the subarray defined by `obj`.
5240 If `axis` is None, `obj` is applied to the flattened array.
5241
5242 Returns
5243 -------
5244 out : ndarray
5245 A copy of `arr` with the elements specified by `obj` removed. Note
5246 that `delete` does not occur in-place. If `axis` is None, `out` is
5247 a flattened array.
5248
5249 See Also
5250 --------
5251 insert : Insert elements into an array.
5252 append : Append elements at the end of an array.
5253
5254 Notes
5255 -----
5256 Often it is preferable to use a boolean mask. For example:
5257
5258 >>> arr = np.arange(12) + 1
5259 >>> mask = np.ones(len(arr), dtype=np.bool)
5260 >>> mask[[0,2,4]] = False
5261 >>> result = arr[mask,...]
5262
5263 Is equivalent to ``np.delete(arr, [0,2,4], axis=0)``, but allows further
5264 use of `mask`.
5265
5266 Examples
5267 --------
5268 >>> import numpy as np
5269 >>> arr = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])
5270 >>> arr
5271 array([[ 1, 2, 3, 4],
5272 [ 5, 6, 7, 8],
5273 [ 9, 10, 11, 12]])
5274 >>> np.delete(arr, 1, 0)
5275 array([[ 1, 2, 3, 4],
5276 [ 9, 10, 11, 12]])
5277
5278 >>> np.delete(arr, np.s_[::2], 1)

Callers 7

test_fancyMethod · 0.90
test_0dMethod · 0.90
test_subclassMethod · 0.90

Calls 8

onesFunction · 0.90
sliceFunction · 0.85
emptyFunction · 0.85
wrapMethod · 0.80
astypeMethod · 0.80
itemMethod · 0.80
ravelMethod · 0.45
copyMethod · 0.45

Tested by 7

test_fancyMethod · 0.72
test_0dMethod · 0.72
test_subclassMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…