# Calling Column of a Matrix using Function | Linear Algebra using Python

Linear Algebra using Python | Calling Column of a Matrix using Function: Here, we are going to learn how to call column of a matrix using function in Python?
Submitted by Anuj Singh, on May 21, 2020

Prerequisite: Linear Algebra | Defining a Matrix

Linear algebra is the branch of mathematics concerning linear equations by using vector spaces and through matrices. Matrix is the key to linear algebra.

All the linear algebra revolves around matrices. Columns are the heart of a Matrix. From column space to null space of a matrix is based on Columns. Therefore, whenever we have to go for Column operations, then we have to call our columns. A function provides a reproducibility feature to the program and therefore it is good to build a function for calling the desired column.

## Python code for Calling Column of a Matrix using Function

```# Linear Algebra Learning Sequence
# Calling Column of a Matrix using Function
import numpy as np

# Use of np.array() to define a matrix
V = np.array([[1,2,3],[2,3,5],[3,6,8],[323,623,823]])
print("--The Matrix-- \n", V)

c = int(input("Enter j (column number) : "))

# Defining function for calling column of matrix
def col(M,c):
coli = []
for i in range(len(M)):
coli.append(M[i][c-1])
return coli

C = col(V,c)

for i in range(len(C)):
print("Component [",i,"] [",c-1,"] :", C[i])
```

Output:

```RUN 1:
--The Matrix--
[[  1   2   3]
[  2   3   5]
[  3   6   8]
[323 623 823]]
Enter j (column number) : 3
Component [ 0 ] [ 2 ] : 3
Component [ 1 ] [ 2 ] : 5
Component [ 2 ] [ 2 ] : 8
Component [ 3 ] [ 2 ] : 823

RUN 2:
--The Matrix--
[[  1   2   3]
[  2   3   5]
[  3   6   8]
[323 623 823]]
Enter j (column number) : 1
Component [ 0 ] [ 0 ] : 1
Component [ 1 ] [ 0 ] : 2
Component [ 2 ] [ 0 ] : 3
Component [ 3 ] [ 0 ] : 323
```

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates