Python for AILesson 4
Lesson 49 min
NumPy
Fast numerical arrays — the foundation of ML in Python.
What you will learn
- ✓Creating NumPy arrays
- ✓Vectorised math (no loops)
- ✓Why NumPy is fast
Explanation
NumPy provides the ndarray, a fast, typed array. Almost every ML library is built on it.
Its superpower is vectorisation: you do math on whole arrays at once instead of looping element by element, which is far faster and cleaner.
Think of NumPy arrays as the numbers your models actually consume.
Code Example
python
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
Real-world use
When a model takes an image as input, that image is a NumPy array of pixel numbers.
Common mistakes
- • Looping over a NumPy array in pure Python instead of using vectorised operations.
Practice
Create a NumPy array of 5 numbers and print its mean, max, and the array doubled.
Knowledge check
0/1 answered1. What is NumPy's main advantage for ML?
Answer all questions to check.