0Pricing
Python Academy · Lesson

Array Operations and Broadcasting

Perform vectorized arithmetic and understand broadcasting rules.

Vectorised Arithmetic

NumPy applies arithmetic element-wise across entire arrays without Python loops — executed in optimised C code.

import numpy as np

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

Universal Functions (ufuncs)

NumPy's ufuncs apply element-wise C-level functions: np.sqrt, np.exp, np.log, np.sin, etc.

import numpy as np

x = np.linspace(0, np.pi, 5)
print(np.sin(x))   # [0. 0.707 1. 0.707 0.]
print(np.exp([1.0, 2.0, 3.0]))   # [2.718 7.389 20.086]

All lessons in this course

  1. NumPy Arrays and dtypes
  2. Array Operations and Broadcasting
  3. Indexing, Slicing, and Fancy Indexing
  4. Linear Algebra with NumPy
← Back to Python Academy