pytorchdot-producttensordot

Calculate vector of dot products


how do i do the following dot product preferably using pytorch tensordot()

Let say i have vector A and vector B :

[a1,a2] . [b1,b2,b3] =

I want to get as a result :

[
  a1 * b1 + a2 * b1,

  a1 * b2 + a2 * b2,

  a1 * b3 + a2 * b3
]

vector by vector = vector of dot products


Solution

  • Einsum might be handy:

    torch.einsum('i,j->j', torch.Tensor(a), torch.Tensor(b))