How to access a NumPy array by column Last Updated : 26 Jun, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report 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: print(NumPy_array_name[:, 2])Output: [6 7 2]Explanation: printing 3rd columnLet's explore different ways to access 'i th' column of a 2D array in Python.Using slicingSlicing is the easiest and fastest way to access a specific column in a NumPy 2D array using arr[:, column_index], where : selects all rows and column_index picks the desired column.Syntax:NumPy_array_name[ : ,column] Python import numpy as np a= [[1, 13, 6], [9, 4, 7], [19, 16, 2]] b = np.array(a) print(b[:, 2]) Output[6 7 2] Explanation: list a is converted into array b.b[:, 2] prints the third column (all rows, column index 2).Using transposeTranspose the given array using the .T property and pass the index as a slicing index to print the array. Python import numpy as np a = np.array([[1, 13, 6], [9, 4, 7], [19, 16, 2]]) c= a.T[2] print(c) Output[6 7 2] Explanation: a is transposed using .T, swapping rows with columns.arr.T[2] accesses the third column as a row and prints it.Using list comprehensionHere, we access the ith element of the row and append it to a list using the list comprehension and printed the col. Python import numpy as np a = np.array([[1, 13, 6], [9, 4, 7], [19, 16, 2]]) c = [row[1] for row in a] print(c) Output:[13, 4, 16]Explanation: a is converted into array.c extracts and prints the second element (index 1) from each row.Using ellipsisEllipsis (...) lets you select rows or columns without writing full slices. It’s useful for accessing data in multi-dimensional arrays.Syntax:numpy_Array_name[...,column] Python import numpy as np a = [[1, 13, 6], [9, 4, 7], [19, 16, 2]] b = np.array(a) print(b[..., 0]) Output[ 1 9 19] Explanation: b[..., 0] prints the first column (index 0) of the array using ellipsis (...) to select all rows.Related Articles:NumPyPython arrayArray slicingList comprehension Comment More infoAdvertise with us Next Article How to access different rows of a multidimensional NumPy array? T technikue20 Follow Improve Article Tags : Python Python-numpy Python numpy-Indexing Practice Tags : python Similar Reads How to swap columns of a given NumPy array? Swapping columns of a NumPy array means exchanging the positions of two specified columns across all rows. For example, if you have a 3x3 array with values like [[0, 1, 2], [3, 4, 5], [6, 7, 9]] and you swap column 0 with column 2, the array becomes [[2, 1, 0], [5, 4, 3], [9, 7, 6]]. Letâs explore d 4 min read How to access different rows of a multidimensional NumPy array? Let us see how to access different rows of a multidimensional array in NumPy. Sometimes we need to access different rows of multidimensional NumPy array-like first row, the last two rows, and even the middle two rows, etc. In NumPy , it is very easy to access any rows of a multidimensional array. Al 3 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 Convert images to NumPy array? Pictures on a computer are made of tiny dots called pixels. To work with them in Python, we convert them into numbers using a NumPy array is a table of numbers showing each pixelâs color. In this article, weâll learn how to do this using popular Python tools.Loading the images via Pillow LibraryLet 5 min read How to Convert NumPy Matrix to Array In NumPy, a matrix is essentially a two-dimensional NumPy array with a special subclass. In this article, we will see how we can convert NumPy Matrix to Array. Also, we will see different ways to convert NumPy Matrix to Array. Convert Python NumPy Matrix to an ArrayBelow are the ways by which we can 3 min read Like