THE CODE READER / PYTHON

example-bf85009a853c.py

Your snippet, in context. Explore the file or visualize its recorded example.

Download raw .py ↓
Complete file
PYTHON / LINE NUMBERS
 1import numpy as np
 2from numpy_core import positions
 3
 4pe = positions(4, 8)
 5np.testing.assert_allclose(pe[0, 0::2], 0)
 6np.testing.assert_allclose(pe[0, 1::2], 1)
 7np.testing.assert_allclose((pe ** 2).sum(axis=-1), 4)
 8
 9robot = np.arange(8, dtype=float) / 8
10at_zero = robot + pe[0]
11at_three = robot + pe[3]
12assert not np.allclose(at_zero, at_three)
13print(pe.shape)  # (4, 8)