Module lessons (1/5)
numpy arrays
Arrays, shape and dtype, vectorisation instead of loops, reshaping and axes.
What you'll learn in this lesson
- Create numpy arrays and read their
shapeanddtype. - Replace slow Python loops with vectorised operations.
- Reshape data and compute statistics along an axis.
Overview
Machine learning means doing the same arithmetic on thousands of numbers. A Python list can hold numbers, but it cannot add two lists element by element ([1, 2] + [3, 4] glues them together). numpy gives you the ndarray: a block of numbers of one type that supports fast, element-wise maths with no loop.
This style, one expression applied to whole arrays, is called vectorisation. It is shorter, clearer and much faster than a loop.
Sections covered in this lesson
- 1The hook: why not plain lists?
- 2Interactive lab: ndarray axes and shape
- 3Quick Python list vs. NumPy ndarray reference
- 4Shape and dtype
- 5Reshaping
- 6Statistics along an axis
Unlock "numpy arrays" and the full Machine Learning: from first principles to practice curriculum
Arrays, shape and dtype, vectorisation instead of loops, reshaping and axes.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in Machine Learning: from first principles to practice plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.