简体   繁体   中英

Dot product of rows in 2 matrices

So I basically have matrices

a = [x1,y1,z1
     x2,y2 z2
     .....
     xN,yN,zN]

and b = [i1,j1,k1 i2,j2,k2 ....]

and want to take the dot product of row 1 of a with row 1 of b, row 2 of a with row 2 of b and so on. They are both shape (3,71216) but

np.dot(a,b) 

gives ValueError: objects are not aligned. Any help would be greatly appreciated.

This is because np.dot is expecting the number of rows of the first argument to equal the number of columns of the second, as the error message suggests.

You will need align the arrays:

np.dot(a, b.T)

Your question is confusing because you say the arrays have shape (3, 71216), but your examples show the transpose (71216, 3).

Anyway, it sounds like you just want this, not a dot product:

(a * b).sum(axis=0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM