Python | Get Kth Column of Matrix (original) (raw)

Last Updated : 1 Nov, 2025

In this article, we will discuss how to extract the Kth column from a matrix in Python.

**Example:

Matrix = [[4, 5, 6],
[8, 1, 10],
[7, 12, 5]]

The 2nd column (K=2, 0-indexed) would be [6, 10, 5].

Let's look at the different methods below to do it in Python:

Using NumPy

NumPy is a high-performance library for numerical computations. Converting a list of lists into a NumPy array allows vectorized operations, which are faster and more memory-efficient compared to Python loops.

Python `

import numpy as np mat = [[4, 5, 6], [8, 1, 10], [7, 12, 5]] K = 2 res = np.array(mat)[:, K] print(res)

`

**Explanation:

Using List Comprehension

Iterates over each row and picks the Kth element. This is clean, Pythonic, and memory-efficient.

Python `

mat = [[4, 5, 6], [8, 1, 10], [7, 12, 5]] K = 2 res = [row[K] for row in mat] print( res)

`

**Explanation:

Using map()

Applies a lambda function to extract the Kth element from each row. The map() function is slightly less intuitive but works efficiently.

Python `

mat = [[4, 5, 6], [8, 1, 10], [7, 12, 5]] K = 2 res = list(map(lambda row: row[K], mat)) print( res)

`

**Explanation:

Using zip()

Transposes the matrix with zip(*) and selects the Kth row of the transposed matrix. This method is readable but slightly slower due to creating intermediate tuples.

Python `

mat = [[4, 5, 6], [8, 1, 10], [7, 12, 5]] K = 2

res = list(zip(*mat))[K] print( res)

`

**Explanation:

Using a For Loop

Manually iterates through each row, appending the Kth element to a new list. This is simple and beginner-friendly but verbose.

Python `

mat = [[4, 5, 6], [8, 1, 10], [7, 12, 5]] K = 2 res = [] for row in mat: res.append(row[K]) print( res)

`

**Explanation: