Chapter 9

NumPy Arrays

Arrays versus lists, creating arrays, shape, dtype, axes, indexing, slicing, views, copies, reductions, and array errors.

Subject
Python
Lessons
7 lessons
Practice
12 checks
Review
3 pages

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.

  1. 01
    Arrays Versus Lists

    Lists as flexible containers, arrays as shaped numerical containers, and why addition differs.

  2. 02
    Creating Arrays

    Creating vectors, matrices, zeros, ones, ranges, and small inspectable arrays.

  3. 03
    Shape, Dtype, and Axis

    The three facts to inspect before array computation: shape, dtype, and axis meaning.

  4. 04
    Indexing and Slicing Arrays

    Selecting scalar values, rows, columns, and slices from one- and two-dimensional arrays.

  5. 05
    Views and Copies

    When slices may share data with the original array and when to copy before mutation.

  6. 06
    Reductions

    Summarizing arrays with sums, means, minima, maxima, and axis-specific reductions.

  7. 07
    Array Errors

    Shape mismatches, dtype surprises, index errors, and the debugging checklist.

  1. Conclusion

    How shape and dtype inspection prepare readers for array computation.

  2. Review

    A compact review of arrays, shape, dtype, axes, indexing, views, copies, reductions, and errors.

  3. Exercises

    Chapter-level practice for creating, inspecting, slicing, copying, and reducing arrays.

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

Chapter progress