Embedding mini-languages in Python has a long tradition. In this section of the tutorial, we will explore some examples of this practice.
The first example we will consider is so-called broadcasting in numpy. It may look shallow at first sight, but it and its associated operations constitute a considerable subset of the array programming language APL.
import numpy as np
a = np.arange(4)
b = np.arange(3) * 10
print(a)
print(b)
a.reshape(-1, 1).shape
x = a.reshape(-1, 1) + b
x
np.sum(x, axis=0)