The numpy library in Python is the primary tool for computing inner products and vector norms.
Linear Algebra
PROGRAMMES
IN PYTHON AND C LANGUAGES
UNIT − III:
INNER PRODUCT SPACES
The
numpy library in Python is the primary tool for computing inner products and
vector norms.
The
inner product of two vectors is calculated by multiplying their corresponding
elements and summing the results. For higher dimensional arrays (matrices),
numpy.inner() performs a sum product over the last axes.
Python
import numpy as np
#Define two vectors
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
# Compute the inner product
inner_product = np.inner (a,b)
print (f"inner product of a and b: (inner product}")
# For matrices, it computes the inner product of rows
x = np.array([[1, 21, [3, 4]])
y = np.array([[5, 6], [7, 8]])
inner_product_matrix = np.inner (x,y)
print (f"inner product of matrices x and y: \n
{inner_product_matrix}")
Vector
norms measure the "length" or "magnitude" of vector
numpy.linalg.norm() is used for this purpose and can compute various types of
norms based on the ord parameter.
Python
import numpy as np
v = np.array([3, 4])
#L2 Norm (Euclidean Norm) ‒ default behavior
12_norm = np.linalg.norm(v)
print (f"L2 Norm of v: {12_norm}")
#L1 Norm (Manhattan Norm)
11_norm = np.linalg.norm (v, ord‒1)
print (f"Ll Norm of v; {11_norm}")
# Max Norm (Infinity Norm)
max norm = np.linalg.norm (v,ord‒np.inf)
print (f"Max Norm of of v: {max_norm}")
# Squared L2 Norm (can be computed using inn product)
squared_12_norm = np.inner (v, v)
print (f"Squared L2 Norm of v: {squared_12_norm}")
Linear Algebra: Practice Programs in Python and C Languages : Tag: maths, mathematics : - Computation of Inner Products and Vector Norms by Using Python (Linear Algebra: Inner Product Spaces)
Linear Algebra
MA25C02 2nd Semester | 2025 Regulation
English Essentials II
EN25C02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Tamils and Technology தமிழர்களும் தொழில்நுட்பமும்
UC25H02 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