Chapter 10

Numerical Data with NumPy

Represent one small numerical table as an array, then inspect, select, reshape, summarize, copy, and repair it without losing the meaning of its axes.

Python lists helped us collect and transform values whose length or contents could change. Numerical work often has a more regular structure: the same sensors are measured for each observation, and an operation should follow corresponding positions. NumPy arrays make that structure part of the value.

One table continues through this chapter. It contains three observations and two sensors, so its shape is `(3, 2)`. We will construct it, name both axes, select by position and condition, exchange or regroup its layout, and compute one summary per sensor. Every result remains small enough to predict and check by hand.

Some selections share stored data with their source and others do not. We will make that relationship visible before changing values. The final lesson uses shape, dtype, dimensions, axis meaning, and small examples to repair a faulty assumption. Broader whole-array computation begins only after this structural model is secure.

After this chapter

  • Choose a list or array from the structure and operation the program needs.
  • Construct small arrays from existing values, a shape, a step rule, or a value-count rule.
  • Inspect shape, ndim, size, and dtype while naming observations and sensors as semantic axes.
  • Select scalars, rows, columns, regions, and condition-matching values with predicted result shapes.
  • Distinguish regrouping entries with reshape from exchanging axes with transpose.
  • Compute and hand-check one summary per sensor by reducing the observation axis.
  • Use storage evidence and explicit copies to make mutation relationships intentional.
  • Diagnose and verify a repair from values, shape, dtype, ndim, axis meaning, and the final error.

Lessons

  1. 01
    Move from Lists to Arrays

    Contrast list concatenation with elementwise array addition and choose each container from the work it must support.

    3 exercises
  2. 02
    Create Small Arrays

    Create small arrays deliberately with array, zeros, ones, arange, linspace, shape tuples, and an explicit dtype when needed.

    3 exercises
  3. 03
    Read Shape, Dtype, and Axis Meaning

    Inspect shape, ndim, size, and dtype, then attach observations and sensors to the correct axes.

    3 exercises
  4. 04
    Select by Position

    Use multidimensional indices, slices, negative positions, and axis-preserving slices with explicit result shapes.

    3 exercises
  5. 05
    Select by Condition

    Inspect mask values and shape, select readings above a threshold, and select rows from one stated sensor condition.

    3 exercises
  6. 06
    Reshape and Transpose

    Form a three-by-two table, use one inferred length, transpose reversed axes, and keep entry count and axis meaning explicit.

    3 exercises
  7. 07
    Summarize Along an Axis

    Calculate one mean per sensor, verify one by hand, and preserve a reduced axis only for a visible alignment need.

    3 exercises
  8. 08
    Distinguish Views and Copies

    Compare basic-slice and transpose views, Boolean-selection copies, storage-dependent reshape sharing, and explicit independent copies.

    3 exercises
  9. 09
    Diagnose Array Assumptions

    Repair malformed structure and invalid mask, index, dtype, or axis assumptions with a small evidence-led method.

    3 exercises

Review and practice

  1. Review

    Review one observations-by-sensors table without introducing broader array computation.

  2. Exercises

    Apply Chapter 10 through twelve cumulative prediction, calculation, implementation, and repair exercises.

Chapter progress