0PricingLogin
Learn AI with Python · Lesson

Broadcasting and Vectorized Operations

How broadcasting works, element-wise operations, avoiding loops with vectorization.

Why Vectorize?

NumPy operates on whole arrays at C speed. Replacing Python loops with array expressions, called vectorization, is often 10 to 100 times faster.

Element-wise Operations

Arithmetic operators apply element by element when shapes match. No loop required.

import numpy as np
a = np.array([1, 2, 3])
b = np.array([10, 20, 30])
print(a + b)   # [11 22 33]
print(a * b)   # [10 40 90]

All lessons in this course

  1. Array Creation and Properties
  2. Indexing, Slicing, and Fancy Indexing
  3. Broadcasting and Vectorized Operations
  4. Linear Algebra with NumPy
← Back to Learn AI with Python