Is there a numpy method to create a 2D array from the addition of two 1D arrays?

前端 未结 1 378
遥遥无期
遥遥无期 2020-12-12 01:15

Basically, s_{i,j} = a_i + b_j

if n=len(a) and m=len(b), then s.shape is (n,m). Thus, the addition a

相关标签:
1条回答
  • 2020-12-12 01:51

    Yes, there actually is. numpy ufuncs have an outer method:

    s = np.add.outer(a, b)
    
    0 讨论(0)
提交回复
热议问题