Chapter 9
NumPy Arrays
Arrays versus lists, creating arrays, shape, dtype, axes, indexing, slicing, views, copies, reductions, and array errors.
What this chapter does
NumPy arrays are the working data structure for numerical Python. This chapter makes shape, dtype, and axis inspection ordinary before the reader moves into heavier array computation.
Lessons
Read these in order.
The chapter opening gives the main idea. Move through these lessons next; each page reuses ideas from the pages before it.
- 01Arrays Versus Lists
Lists as flexible containers, arrays as shaped numerical containers, and why addition differs.
- 02Creating Arrays
Creating vectors, matrices, zeros, ones, ranges, and small inspectable arrays.
- 03Shape, Dtype, and Axis
The three facts to inspect before array computation: shape, dtype, and axis meaning.
- 04Indexing and Slicing Arrays
Selecting scalar values, rows, columns, and slices from one- and two-dimensional arrays.
- 05Views and Copies
When slices may share data with the original array and when to copy before mutation.
- 06Reductions
Summarizing arrays with sums, means, minima, maxima, and axis-specific reductions.
- 07Array Errors
Shape mismatches, dtype surprises, index errors, and the debugging checklist.
You are ready when
- Explain how arrays differ from lists.
- Create small vectors and matrices.
- Inspect shape, dtype, and axis meaning.
- Select rows, columns, and slices.
- Distinguish views from copies before mutation.
- Compute row and column reductions.
- Debug common array shape and dtype errors.
Where this leads
- Array Computation
- Plotting and Inspection
- Small Numerical Experiments