Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Master Data Science with Python

Lesson 12 of 60 · python

Linear Algebra Basics with NumPy

Duration: 30 minutes

Linear Algebra Basics

Linear algebra is at the heart of many data‑science algorithms (e.g., PCA, regression).

Why it matters

  • Vectors represent features.
  • Matrices represent data tables or transformations.

Performing basic operations

import numpy as np

# Dot product (vector)
v = np.array([1, 2, 3])
w = np.array([4, 5, 6])
print('Dot:', np.dot(v, w))   # or v @ w

# Matrix multiplication
A = np.array([[1, 2], [3, 4]])
B = np.array([[5, 6], [7, 8]])
C = A @ B
print('A @ B =\n', C)

Solving linear systems

A = np.array([[3, 1], [1, 2]])
b = np.array([9, 8])
solution = np.linalg.solve(A, b)
print('Solution:', solution)

Eigenvalues & eigenvectors

vals, vecs = np.linalg.eig(A)
print('Eigenvalues:', vals)
print('Eigenvectors:\n', vecs)

Singular Value Decomposition (SVD)

U, S, VT = np.linalg.svd(A)
print('U:\n', U)
print('S:', S)
print('VT:\n', VT)

Info

Standardize data before PCA – otherwise scale dominates the components.

Previous: Random Sampling and Statistics with NumPyNext: Advanced NumPy: Masking, Fancy Indexing, and Structured Arrays