Arrays and types
Why NumPy is fast, the many ways to create arrays, and how dtypes decide what an array can hold and how arithmetic behaves.
About 5 hours of study
Learning objectives
- Explain why arrays beat lists for numbers
- Create arrays with array, zeros, arange and linspace
- Predict and change dtypes
Lessons
- 1
Why NumPy Intermediate
What NumPy is, how its arrays differ from Python lists, why whole-array operations are fast, and how this course models NumPy in plain Python so every exercise runs in your browser.
- 2
Creating arrays Intermediate
The ways to make arrays: from lists with np.array, filled with zeros, ones or a value, evenly spaced with arange and linspace, identity matrices with eye, and choosing the shape and dtype as you create them.
- 3
Data types: dtype Intermediate
Why every array has one dtype, the common types (bool, integers, floats), how NumPy chooses the dtype of a result, converting with astype, and the surprises of fixed-size integers and floats.
Module practice
- NumPy: Add two arrays element-wiseEasy
- NumPy: Shape, ndim and sizeMedium
- NumPy: Print a matrix the way NumPy doesHard
- NumPy: Model np.arangeEasy
- NumPy: Model np.linspaceMedium
- NumPy: zeros, ones, full and eyeHard
- NumPy: The dtype of a resultEasy
- NumPy: Convert with astypeMedium
- NumPy: Fixed-size integers that wrap aroundHard