Python Forum
comparing each rows of two matrix
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
comparing each rows of two matrix
#1
I have two numpy-matrices ("A" and "B"). I want to compare every row-vector in "A" matrix with every row-vector in "B" matrix.

Here is my (not working) code. The expected output is 5.

import numpy as np
a=np.matrix([[1,2,3],[42,68,69],[1,2,3],[85,89,95]])
b=np.matrix([[42,68,69],[1,2,3],[85,89,95], [42,68,69]])


found_one=0
for i in range(3):
    for j in range(3):
        if a[i,]==b[j,]]:
            found_one=found_one+1
            
print(found_one)
Any suggestion?
Reply


Messages In This Thread
comparing each rows of two matrix - by PhysChem - Apr-18-2019, 06:17 AM
RE: comparing each rows of two matrix - by PhysChem - Apr-18-2019, 12:03 PM
RE: comparing each rows of two matrix - by DeaD_EyE - Apr-18-2019, 12:19 PM
RE: comparing each rows of two matrix - by PhysChem - Apr-21-2019, 03:13 PM
RE: comparing each rows of two matrix - by PhysChem - May-14-2019, 09:22 AM
RE: comparing each rows of two matrix - by PhysChem - May-16-2019, 09:47 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020