You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
NumPy (Numerical Python) is the foundational library for numerical computing in Python. It provides a powerful N-dimensional array object, broadcasting functions, and tools for integrating C/C++ and Fortran code. Nearly every data science library in Python — Pandas, Matplotlib, Scikit-Learn, TensorFlow — is built on top of NumPy.
Python lists are flexible but slow for numerical computation. NumPy arrays are:
| Feature | Python List | NumPy Array |
|---|---|---|
| Speed | Slow (interpreted loops) | Fast (compiled C code) |
| Memory | High overhead per element | Compact, contiguous memory |
| Operations | Element-by-element loops required | Vectorised operations |
| Broadcasting | Not supported | Automatic shape matching |
| Type | Mixed types allowed | Homogeneous type |
A NumPy operation on a million elements can be 100x faster than the equivalent Python loop.
import numpy as np
# 1D array
a = np.array([1, 2, 3, 4, 5])
print(a) # [1 2 3 4 5]
print(type(a)) # <class 'numpy.ndarray'>
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.