1

I have two batches of vectors : W= [w1,w2, w3,...]

and

V= [v1,v2,v3,...].

Both batches are expressed in numpy 2D vectors [[x1, y1], [x2,y2]...]

I want to calculate the pairwise dot product between any element in W and a element in V, and i want a matrix of possible combinations, i.e

[ w1.v1 , w1.v2 , w1.v3,...

w2.v1 , w2.v2 , w2.v3,...

w3.v1 , w3.v2 , w3.v3,...

....................................... ]

if w and v are simple scalars then this is easy.

But the problem is w and v are 1D vectors : [x, y]

How do I implement this in numpy?

Thanks

Abel Tan
  • 45
  • 4

1 Answers1

0

Assuming that you want to compute the dot products of row vectors,

np.einsum('ji,ki-> jk', V, W)

If column vectors

np.einsum('ij,ik-> jk', V, W)
Igor Rivin
  • 4,632
  • 2
  • 23
  • 35
  • hello, im a noob at Einstein Summation. What do you mean by column and row vectors? – Abel Tan May 24 '20 at 04:45
  • @AbelTan you have an array [[a, b, c], [d, e, f]] and another [[x, y, z], [w, s, t]] Is your result a 3x3 array (so you take the dot products of the columns of the original arrays( or 2x2 (so you take dot products of rows)? In the latter case, the first recipe works, in the former, the second. – Igor Rivin May 24 '20 at 04:47
  • its a 3x3 array, so i take the second recipe? – Abel Tan May 24 '20 at 06:22