Home > Mobile >  Vectorizing addition
Vectorizing addition

Time:06-04

Let's say I have two numpy arrays a[n,3] and b[m,3]

How do I calculate c[n,m,3] , without resorting to a for loop, such as:

c[i,j,:] = a[i,:] b[j,:]

CodePudding user response:

Try this:

c = a[:, None, :]   b[None, :, :]
  • Related