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
#3
If I correctly understand the objective (which in doubt) in 'pure' Python it could be done this way:

>>> a = [[1,2,3],[42,68,69],[1,2,3],[85,89,95]]
>>> b= [[42,68,69],[1,2,3],[85,89,95], [42,68,69]]
>>> len([(x, y) for x in a for y in b if x == y])
5
To 'translate' this into numpy array it needs little adjustments:

>>> 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]])
>>> len([(x, y) for x in a for y in b if np.array_equal(x, y)])
5
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
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 perfringo - Apr-18-2019, 09:11 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