sofeikov / numty
Static shape checking for NumPy: one mypy plugin, precise shapes before anything runs
numty
Static shape checking for NumPy.
Wrong-shaped arrays become mypy errors, before anything runs
Documentation · Get started · Bug gallery · Limitations
That file imports nothing from numty and annotates nothing. numty worked out that reshape(64, -1) of (64, 28, 28) is (64, 784), carried it into the @, and saw that sum(axis=1) drops an axis the division needs.
The second bug is the dangerous kind. With 10 samples instead of 64, NumPy would broadcast (10, 10) / (10,) without complaint and return probabilities normalised along the wrong axis.
import numpy as np images = np.zeros((64, 28, 28)) weights = np.zeros((10, 784)) # transposed: should be (784, 10) bias = np.zeros(10) flat = images.reshape(64, -1) logits =…