Course materials · Introduction to Machine Learning

NumPy · Study

English translation

Topics covered

Practice calculating aggregates by sample and by feature without confusing rows and columns.

Assign meaning to array axes

If rows represent measurement times and columns represent sensor channels, axis=0 aggregation summarizes each channel. A correct Shape does not ensure the intended calculation. Choose elementwise or matrix multiplication according to its physical meaning.

Time and noise

To interpret differences as velocity, divide by the measurement time interval. A moving average reduces noise but blurs abrupt changes, and the sample count may differ at boundaries. Compare before and after filtering over the same time interval.

Worked example

X=[246135024357]X=\begin{bmatrix}2&4&6\\1&3&5\\0&2&4\\3&5&7\end{bmatrix}, where rows are samples and columns are features.

import numpy as np
import matplotlib.pyplot as plt
X=np.array([[2,4,6],[1,3,5],[0,2,4],[3,5,7]])
print(X.mean(axis=0),X.mean(axis=1))
[1.5 3.5 5.5] [4. 3. 2. 5.]

Reference example

View more examples

Reference materials