a = np.array([1, 2, 3])
b = np.array([4, 5])

def f(i, j):
    return i + j
result = np.array([[f(i, j) for j in b] for i in a])
print(result)
Numpy quirk: Apply function to all pairs of two 1D arrays, to get one 2D array