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, :, :]
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, :, :]