How to Retrieve an Entire Row or Column of an Array in Python? Last Updated : 27 May, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Retrieving an entire row or column from an array in Python is a common operation, especially when working with matrices or tabular data. This can be done efficiently using different methods, especially with the help of NumPy. Let’s explore various ways to retrieve a full row or column from a 2D array.Using numpy indexingThis is the most common and efficient method. NumPy allows you to use square brackets ([]) to slice rows and columns just like lists but with powerful features. Python import numpy as np a = np.array([[1, 2, 3],[4, 5, 6],[7, 8, 9]]) r = a[1] c = a[:, 2] print(r,c) Output[4 5 6] [3 6 9] Explanation: a[1] retrieves the second row and a[:, 2] extracts the third column by selecting all rows at column index 2.Using np.take()np.take() is a NumPy function that selects elements along a specific axis (rows or columns). It's helpful when you're dynamically selecting elements and want a bit more control. Python import numpy as np a = np.array([[1, 2, 3],[4, 5, 6],[7, 8, 9]]) r= np.take(a, indices=1, axis=0) c = np.take(a, indices=2, axis=1) print(r,c) Output[4 5 6] [3 6 9] Explanation: np.take(a, indices=1, axis=0) retrieves the second row (index 1) by selecting along rows (axis=0).np.take(a, indices=2, axis=1) retrieves the third column (index 2) by selecting along columns (axis=1).Using np.squeeze()When you slice a specific row or column, NumPy may return it as a 2D array. np.squeeze() removes any unnecessary dimensions, giving you a clean 1D array. Python import numpy as np a = np.array([[1, 2, 3],[4, 5, 6],[7, 8, 9]]) r = np.squeeze(a[1:2, :]) c = np.squeeze(a[:, 2:3]) print(r, c) Output[4 5 6] [3 6 9] Explanation:a[1:2, :] gets the second row as a 2D array (1, 3), and np.squeeze() flattens it to [4, 5, 6].a[:, 2:3] gets the third column as (3, 1) and np.squeeze() converts it to [3, 6, 9].Using list comprehensionIf you're not using NumPy or you're working with pure Python lists, you can manually loop through rows to get a specific column. It's slower and not recommended for large data, but it's good for understanding how things work under the hood. Python import numpy as np a = np.array([[1, 2, 3],[4, 5, 6],[7, 8, 9]]) r = list(a[1]) c = [row[2] for row in a] print(r, c) Output[np.int64(4), np.int64(5), np.int64(6)] [np.int64(3), np.int64(6), np.int64(9)] Explanation:list(a[1]) converts the second row to a regular Python list.[row[2] for row in a] uses list comprehension to extract the third element from each row, forming the column.Related articlesnumpynp.take()np.squeeze()list comprehension Comment More infoAdvertise with us Next Article How to convert 1-D arrays as columns into a 2-D array in Python? M mallikagupta90 Follow Improve Article Tags : Python Python-numpy Practice Tags : python Similar Reads How to get the address for an element in Python array? In this article we are going to discuss about getting the address of an particular element in the Python array. In python we can create the array using numpy. Numpy stands for numeric python used to create and process arrays. We have to import numpy module import numpy as np Syntax to create array: 3 min read How to convert 1-D arrays as columns into a 2-D array in Python? Let's see a program to convert 1-D arrays as columns into a 2-D array using NumPy library in Python. So, for solving this we are using numpy.column_stack() function of NumPy. This function takes a sequence of 1-D arrays and stack them as columns to make a single 2-D array. Syntax : numpy.column_stac 1 min read How to extract a particular column from 1D array of tuples? In this article, we will cover how to extract a particular column from a 1-D array of tuples in python. Example Input:  [(18.18,2.27,3.23),(36.43,34.24,6.6),(5.25,6.16,7.7),(7.37,28.8,8.9)] Output: [3.23, 6.6 , 7.7 , 8.9 ] Explanation: Extracting the 3rd column from 1D array of tuples. Method 1: Us 2 min read How to get column and row names in DataFrame? While analyzing the real datasets which are often very huge in size, we might need to get the rows or index names and columns names in order to perform certain operations. Note: For downloading the nba dataset used in the below examples Click Here Getting row names in Pandas dataframe First, let's 3 min read Get values of all rows in a particular column in openpyxl - Python In this article, we will explore how to get the values of all rows in a particular column in a spreadsheet using openpyxl in Python. We will start by discussing the basics of openpyxl and how to install and import it. Then, we will walk through for example, how to extract the values of a particular 4 min read How to access a NumPy array by column NumPy arrays are used to handle large datasets efficiently. When working with 2D arrays, you may need to access specific columns for analysis or processing. NumPy makes this easy with simple indexing methods.Representation of rows and column in 2D arrayExample:Given array: 1 13 6 9 4 7 19 16 2Input: 2 min read Like