Shaping, ordering and statistics

Reshaping and joining arrays, sorting, unique values and binary search, and descriptive statistics with percentiles and histograms.

About 5 hours of study

Learning objectives

Lessons

  1. 1

    Reshaping and stacking Intermediate

    Changing an array's shape without changing its data: reshape and the -1 shortcut, flatten and ravel, transposing with .T, and joining arrays with concatenate, vstack, hstack and stack.

  2. 2

    Sorting, unique values and searching Intermediate

    Ordering and finding data with NumPy: np.sort and the in-place sort, argsort for the order of positions, unique values with counts, and fast binary search in sorted arrays with searchsorted.

  3. 3

    Statistics with NumPy Intermediate

    Describing data with NumPy: mean, median and std (and the ddof trap), percentiles with linear interpolation, histograms with np.histogram, correlation with np.corrcoef, and standardising columns.

Module practice

Module quiz

1. What is np.arange(6).reshape(2, -1).shape?
2. Which function gives the positions that would sort an array?
3. What is np.median([3, 1, 2])?
4. np.concatenate of (2, 3) and (2, 4) along axis 1 gives…
5. np.std(a) and pandas' s.std() differ for the same data because…
6. What is np.percentile([10, 20, 30, 40], 50)?

‹ Vectorised computingNumPy in practice ›