Python - Numpy Array Column Deletion Last Updated : 03 Apr, 2023 Comments Improve Suggest changes Like Article Like Report Given a numpy array, write a programme to delete columns from numpy array. Examples - Input: [['akshat', 'nikhil'], ['manjeeet', 'akash']] Output: [['akshat']['manjeeet']] Input: [[1, 0, 0, 1, 0], [0, 1, 2, 1, 1]] Output: [[1 0 1 0][0 2 1 1]] Given below are various methods to delete columns from numpy array. Method #1: Using np.delete() Python3 # Python code to demonstrate # deletion of columns from numpy array import numpy as np # initialising numpy array ini_array = np.array([[1, 0, 0, 1, 0], [0, 1, 2, 1, 1]]) # deleting second column from array result = np.delete(ini_array, 1, 1) # print result print ("Resultant Array :"+str(result)) Output: Resultant Array :[[1 0 1 0] [0 2 1 1]] Time Complexity: O(n) Space Complexity: O(n) where n is length of array Method #2: Using compress() and logical_not() Python3 # Python code to demonstrate # deletion of columns from numpy array import numpy as np # initialising numpy array ini_array = np.array([[1, 0, 0, 1, 0], [1, 2, 0, 0, 1]]) z = [False, True, False, False, False] # deleting second column from array result = ini_array.compress(np.logical_not(z), axis = 1) # print result print ("Resultant Array :"+str(result)) Output: Resultant Array :[[1 0 1 0] [1 0 0 1]] Time Complexity: O(n) Space Complexity: O(n) where n is length of array Method #3: Using logical_not() Python3 # Python code to demonstrate # deletion of columns from numpy array import numpy as np # initialising numpy array ini_array = np.array([[1, 0, 0, 1, 0], [1, 2, 0, 0, 1]]) z = [False, True, False, False, False] # deleting second column from array result = ini_array[:, np.logical_not(z)] # print result print ("Resultant Array :"+str(result)) Output: Resultant Array :[[1 0 1 0] [1 0 0 1]] Time Complexity: O(n) Space Complexity: O(n) where n is length of array Comment More infoAdvertise with us Next Article Python - Numpy Array Column Deletion manjeet_04 Follow Improve Article Tags : Python Numpy Python numpy-arrayManipulation Practice Tags : python Similar Reads NumPy Array in Python NumPy (Numerical Python) is a powerful library for numerical computations in Python. It is commonly referred to multidimensional container that holds the same data type. It is the core data structure of the NumPy library and is optimized for numerical and scientific computation in Python. Table of C 2 min read Delete a CSV Column in Python The comma-separated values ââ(CSV) file is a delimited text file that uses commas for individual values. Each line of the file is a data record in CSV. This format used for tabular data, rows, and columns, exactly like a spreadsheet. The CSV file stores data in rows and the values ââin each row are 3 min read numpy.delete() in Python 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 3 min read Python | Convert Numpy Arrays to Tuples Given a numpy array, write a program to convert numpy array into tuples. Examples - Input: ([[1, 0, 0, 1, 0], [1, 2, 0, 0, 1]]) Output: ((1, 0, 0, 1, 0), (1, 2, 0, 0, 1)) Input: ([['manjeet', 'akshat'], ['nikhil', 'akash']]) Output: (('manjeet', 'akshat'), ('nikhil', 'akash')) Method #1: Using tuple 2 min read Python Lists VS Numpy Arrays Here, we will understand the difference between Python List and Python Numpy array. What is a Numpy array?NumPy is the fundamental package for scientific computing in Python. Numpy arrays facilitate advanced mathematical and other types of operations on large numbers of data. Typically, such operati 7 min read Numpy - Array Creation Numpy Arrays are grid-like structures similar to lists in Python but optimized for numerical operations. The most straightforward way to create a NumPy array is by converting a regular Python list into an array using the np.array() function.Let's understand this with the help of an example:Pythonimp 5 min read Python | Numpy numpy.ndarray.__sub__() With the help of Numpy numpy.ndarray.__sub__(), We can subtract a particular value that is provided as a parameter in the ndarray.__sub__() method. Value will be subtracted to each and every element in a numpy array. Syntax: ndarray.__sub__($self, value, /) Return: self-value Example #1 : In this ex 1 min read How to swap columns of a given NumPy array? In this article, let's discuss how to swap columns of a given NumPy array. Approach : Import NumPy moduleCreate a NumPy arraySwap the column with IndexPrint the Final array Example 1: Swapping the column of an array. Python3 # importing Module import numpy as np # creating array with shape(4,3) my_ 2 min read How to access a NumPy array by column Accessing a NumPy-based array by a specific Column index can be achieved by indexing. NumPy follows standard 0-based indexing in Python.  Example:Given array: 1 13 6 9 4 7 19 16 2 Input: print(NumPy_array_name[ :,2]) Output: [6 7 2] Explanation: printing 3rd columnAccess ith column of a 2D Numpy Arr 3 min read Python | Numpy numpy.ndarray.__isub__() With the help of numpy.ndarray.__isub__() method, we can subtract a particular value that is provided as a parameter in the ndarray.__isub__() method. Value will be subtracted to every element in a numpy array. Syntax: ndarray.__isub__($self, value, /) Return: self-=value Example #1 : In this exampl 1 min read Like