How to Retrieve an Entire Row or Column of an Array in Python? Last Updated : 27 May, 2025 Comments Improve Suggest changes 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 Retrieve an Entire Row or Column of an 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 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 How to get nth row in a Pandas DataFrame? Pandas Dataframes are basically table format data that comprises rows and columns. Now for accessing the rows from large datasets, we have different methods like iloc, loc and values in Pandas. The most commonly used method is iloc(). Let us consider a simple example.Method 1. Using iloc() to access 4 min read How to Change a Single Value in a NumPy Array NumPy arrays are a fundamental data structure in Python, widely used for scientific computing and data analysis. They offer a powerful way to perform operations on large datasets efficiently. One common task when working with NumPy arrays is changing a single value within the array. This article wil 6 min read Program to access different columns of a multidimensional Numpy array Prerequisite: Numpy module The following article discusses how we can access different columns of multidimensional Numpy array. Here, we are using Slicing method to obtain the required functionality. Example 1: (Accessing the First and Last column of Numpy array) Python3 # Importing Numpy module im 3 min read How to read a numerical data or file in Python with numpy? Prerequisites: Numpy NumPy is a general-purpose array-processing package. It provides a high-performance multidimensional array object and tools for working with these arrays. This article depicts how numeric data can be read from a file using Numpy. Numerical data can be present in different forma 4 min read Like