"broadcast" 两个一维数组的元素之和到二维数组的有效方法

Efficient way to "broadcast" the sum of elements of two 1D arrays to a 2D array

有没有更有效的方法(没有循环)用 Numpy 做这个?:

for i, x in enumerate(array1):
    for j, y in enumerate(array2):
        result[i, j] = x + y

我尝试使用 einsum 但没有成功。

谢谢!

简单地使用具有额外维度的广播:

result = array1[:,None]+array2