📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials NumPy Linear Algebra

Linear Algebra

5 min read
Matrix multiply, transpose, invert, find eigenvalues, and solve linear systems with linalg.

Linear Algebra with NumPy

import numpy as np

A = np.array([[1,2],[3,4]])
B = np.array([[5,6],[7,8]])

# Matrix multiplication
A @ B              # modern syntax
np.dot(A, B)       # same

# Element-wise multiplication
A * B

# Transpose
A.T

# Inverse
np.linalg.inv(A)

# Determinant
np.linalg.det(A)   # -2.0

# Eigenvalues and eigenvectors
vals, vecs = np.linalg.eig(A)

# Solve linear system Ax = b
b = np.array([1, 2])
x = np.linalg.solve(A, b)

# Singular Value Decomposition
U, S, Vt = np.linalg.svd(A)

# Norm
np.linalg.norm(A)