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 10 of 60 · python

Mathematical Operations with NumPy

Duration: 25 minutes

Mathematical Operations

NumPy provides a rich set of universal functions (ufuncs) for element‑wise math.

Basic arithmetic

x = np.array([1, 2, 3])
y = np.array([4, 5, 6])
print(x + y)   # [5 7 9]
print(x * y)   # [4 10 18]
print(x ** 2)  # [1 4 9]

Trigonometric functions

angles = np.deg2rad(np.array([0, 30, 45, 60, 90]))
print(np.sin(angles))

Aggregations

arr = np.random.randn(1000)
print("Mean:", arr.mean())
print("Std:", arr.std())
print("Median:", np.median(arr))

Linear Algebra utilities

A = np.array([[1, 2], [3, 4]])
B = np.linalg.inv(A)
print("Inverse of A:\n", B)
print("Determinant:", np.linalg.det(A))

Random sampling

rng = np.random.default_rng(seed=42)
samples = rng.normal(loc=0, scale=1, size=5)
print(samples)

Info

Use np.dot or the @ operator for matrix multiplication.

Previous: Broadcasting in NumPyNext: Random Sampling and Statistics with NumPy