Linear Algebra: Practice Programs in Python and C Languages

Computation of Dimensions of Subspaces in Vectors by Using Python (Linear Algebra: Vector Spaces)

Linear Algebra: Practice Programs in Python and C Languages - Linear Algebra: Vector Spaces: Computation of Dimensions of Subspaces in Vectors by Using Python

Linear Algebra

PROGRAMMES IN PYTHON AND C LANGUAGES

UNIT − 1: VECTOR SPACES

 

COMPUTATION OF DIMENSIONS OF SUBSPACES IN VECTORS BY USING PYTHON

To compute the dimension of a subspace spanned by a set of vectors in Python, we can use the numpy, linalg.matrix_rank function. The dimensions of the subspace is equal to the rank of the matrix formed by the given vectors.

 

Method: Using numpy.lina1g.matrix_rank

The most straightforward way is to form a matrix where each row (or column) represents one of the spanning vectors, and then use the numpy library to compute its rank. The rank of the matrix is the number of linearly independent vectors, which is the dimension of the subspace they span.

Here is the Python code:

python

import numpy as np

def subspace_dimension (vectors):

" " "

Calculates the dimension of the subspace spanned by a list of vector:

Args:

vectors: A list of vectors, where each vector is a list or numpy

Returns:

The dimension of the subspace (integer).

" " "

# Convert the list of vectors into a Numpy matrix.

# The vectors form the rows of the matrix.

vectors_1 = {

[1, 1, 0],

[1, ‒1, 01,

[2, 0, 0]

# This vector is a linear combination of the first two (v)

}

dim_1 = subspace_dimension (vectors_1)

print (f"The dimension of the subspace spanned by vectors 1 is: {dim_1}}

# Another example: A set of vectors that  spans all of R3.

vectors_ 2 = [

[1, 0, 0],

[0, 1, 0],

[0, 0, 1]

]

dim_2= subspace_dimension (vectors-2)

print (f"The dimension of the subspace spanned by vectors 2 is: {dim_2}"

# Example of a ID subspace (a line through the origin)

vectors_3 = [

[1, 2, 3],

[2, 4, 6],

[3,6,9]

]

dim_3= subspace_dimension (vectors_3)

print (f"The dimension of the subspace spanned by vectors 3 is: {dim_3}"

Key concepts

Subspace: A subset of a vector space that is itself a vector space. Subspaces can be lines, planes, etc., passing through the origin.

 

Linear Algebra: Practice Programs in Python and C Languages : Tag: maths, mathematics : - Computation of Dimensions of Subspaces in Vectors by Using Python (Linear Algebra: Vector Spaces)


Linear Algebra: Practice Programs in Python and C Languages



Under Subject


Linear Algebra

MA25C02 2nd Semester | 2025 Regulation



Related Subjects


English Essentials II

EN25C02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation



Linear Algebra

MA25C02 2nd Semester | 2025 Regulation


Transforms and its Applications

MA25C03 2nd Semester EEE Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Applied Physics (CE) II

PH25C02 2nd Semester Civil, Agri Depts | 2025 Regulation | 2nd Semester 2025 Regulation


Applied Physics (CSIE) II

PH25C03 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Applied Physics (EE) II

PH25C04 2nd Semester EEE Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Applied Physics (ME) II

PH25C05 2nd Semester Mechanical Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Applied Chemistry (CE) II

CY25C02 2nd Semester Civil Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Applied Chemistry (ME) II

CY25C03 2nd Semester Mechanical Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Electron Devices

EC25C01 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Digital Principles and Computer Organization

CS25C06 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Basic Electrical and Electronics Engineering

EE25C01 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation


Basic Civil and Mechanical Engineering

GE25C01 2nd Semester EEE Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Data Structures using CPlusPlus

CS25C05 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Engineering Drawing

ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation


Data Structures and Algorithms

CS25C04 2nd Semester EEE Dept | 2025 Regulation


Circuits and Network Analysis

EC25C02 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Engineering Mechanics

ME25C02 2nd Semester Mech, Civil, Agri Depts | 2025 Regulation | 2nd Semester 2025 Regulation


Object Oriented Programming (OOPs)

CS25C07 2nd Semester CSE, CSE(CY) Depts | 2025 Regulation | 2nd Semester 2025 Regulation