numpy.delete() in Python Last Updated : 09 Aug, 2022 Comments Improve Suggest changes Like Article Like Report The numpy.delete() function returns a new array with the deletion of sub-arrays along with the mentioned axis. 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 : An array with sub-array being deleted as per the mentioned object along a given axis. Code 1 : Deletion from 1D array Python # Python Program illustrating # numpy.delete() import numpy as geek #Working on 1D arr = geek.arange(5) print("arr : \n", arr) print("Shape : ", arr.shape) # deletion from 1D array object = 2 a = geek.delete(arr, object) print("\ndeleteing {} from array : \n {}".format(object,a)) print("Shape : ", a.shape) object = [1, 2] b = geek.delete(arr, object) print("\ndeleteing {} from array : \n {}".format(object,a)) print("Shape : ", a.shape) Output : arr : [0 1 2 3 4] Shape : (5,) deleting arr 2 times : [0 1 3 4] Shape : (4,) deleting arr 3 times : [0 3 4] Shape : (4,) Code 2 : Python # Python Program illustrating # numpy.delete() import numpy as geek #Working on 1D arr = geek.arange(12).reshape(3, 4) print("arr : \n", arr) print("Shape : ", arr.shape) # deletion from 2D array a = geek.delete(arr, 1, 0) ''' [[ 0 1 2 3] [ 4 5 6 7] -> deleted [ 8 9 10 11]] ''' print("\ndeleteing arr 2 times : \n", a) print("Shape : ", a.shape) # deletion from 2D array a = geek.delete(arr, 1, 1) ''' [[ 0 1* 2 3] [ 4 5* 6 7] [ 8 9* 10 11]] ^ Deletion ''' print("\ndeleteing arr 2 times : \n", a) print("Shape : ", a.shape) Output : arr : [[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]] Shape : (3, 4) deleting arr 2 times : [[ 0 1 2 3] [ 8 9 10 11]] Shape : (2, 4) deleting arr 2 times : [[ 0 2 3] [ 4 6 7] [ 8 10 11]] Shape : (3, 3) deleting arr 3 times : [ 0 3 4 5 6 7 8 9 10 11] Shape : (3, 3) Code 3: Deletion performed using Boolean Mask Python # Python Program illustrating # numpy.delete() import numpy as geek arr = geek.arange(5) print("Original array : ", arr) mask = geek.ones(len(arr), dtype=bool) # Equivalent to np.delete(arr, [0,2,4], axis=0) mask[[0,2]] = False print("\nMask set as : ", mask) result = arr[mask,...] print("\nDeletion Using a Boolean Mask : ", result) Output : Original array : [0 1 2 3 4] Mask set as : [False True False True True] Deletion Using a Boolean Mask : [1 3 4] References : https://docs.scipy.org/doc/numpy/reference/generated/numpy.delete.htmlNote : These codes won’t run on online IDE's. Please run them on your systems to explore the working . Comment More infoAdvertise with us Next Article numpy.delete() in Python M Mohit Gupta_OMG Improve Article Tags : Python Python-numpy Python numpy-arrayManipulation Practice Tags : python Similar Reads Python | Pandas Index.delete() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.delete() function returns a new object with the passed locations deleted. 2 min read Python Mongodb - Delete_one() Mongodb is a very popular cross-platform document-oriented, NoSQL(stands for "not only SQL") database program, written in C++. It stores data in JSON format(as key-value pairs), which makes it easy to use. MongoDB can run over multiple servers, balancing the load to keep the system up and run in cas 2 min read Python Mongodb - Delete_many() MongoDB is a general-purpose, document-based, distributed database built for modern application developers and the cloud. It is a document database, which means it stores data in JSON-like documents. This is an efficient way to think about data and is more expressive and powerful than the traditiona 2 min read Python MySQL - Delete Query Python Database API ( Application Program Interface ) is the Database interface for the standard Python. This standard is adhered to by most Python Database interfaces. There are various Database servers supported by Python Databases such as MySQL, GadFly, PostgreSQL, Microsoft SQL Server 2000, Info 3 min read What is __del__ in Python? In Python, object-oriented programming provides several special methods that start and end with double underscores, known as "magic methods" or "dunder methods." These methods enable you to customize the behavior of your classes in specific ways. One such method is __del__, which is also known as th 4 min read delattr() and del() in Python In this article, we are going to see delattr() and del() functions in Python delattr() in Python The delattr() method is used to delete the named attribute from the object, with the prior permission of the object. Syntax: delattr(object, name): The function takes only two parameter: object:Â from wh 3 min read Matplotlib.pyplot.delaxes() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. matplotlib.pyplot.delaxes() Function The delaxes() function in pyplot module of matplotlib library is use 2 min read Python delattr() Function In Python, the delattr() function is used to delete an attribute from an object. In this article, we will learn about the Python delattr() function. Python delattr() Syntaxdelattr (object, name) Parameters: Object: An object from which we want to delete the attribute name: The name of the attribute 3 min read Python : __delete__ vs __del__ Both __delete__ and __del__ are dunder or magic methods in Python. Dunder or magic methods in Python are the methods having two prefix and suffix underscores in the method name. Dunder here means âDouble Under (Underscores)â. These are commonly used for operator overloading. __del__ __del__ is a des 2 min read How to delete a CSV file in Python? In this article, we are going to delete a CSV file in Python. CSV (Comma-separated values file) is the most commonly used file format to handle tabular data. The data values are separated by, (comma). The first line gives the names of the columns and after the next line the values of each column. Ap 2 min read Like