Python Forum
Partial "visual" Matching of matrices
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Partial "visual" Matching of matrices
#16
Well thanks for the responses
With your help i have constructed the following (Pandas is great !!! )
import pandas as pd

def noOfDifferentElements(matrix1,matrix2):
    pinput1 = pd.DataFrame(matrix1)
    pinput2 = pd.DataFrame(matrix2)
    dfBool = (pinput1 != pinput2).stack()
    diff = pd.concat([pinput1.stack()[dfBool],pinput2.stack()[dfBool]],axis=1)
    print("No of Differece Matrix1 & Matrix2 : {difference}".format(difference=diff.size/2))

# converting your input data to a valid Python object:
A = """
1 0 1 1 1 0 0 1
1 0 0 1 1 0 0 1
1 0 1 0 0 0 0 0
1 0 0 0 1 0 0 1
""".strip()

B = """
0 1 0 0 1 0 0 1
1 1 0 0 0 0 0 1
1 1 1 0 0 0 0 1
1 0 1 0 1 0 0 1
""".strip()

C = """
1 0 1 0 1 0 0 1
1 0 1 1 1 0 0 1
1 0 1 0 0 0 0 1
1 1 0 0 1 0 0 1
""".strip()

# nested list comprehension to create the matrix
a = [[int(d) for d in a.split()] for a in A.splitlines()]
b = [[int(d) for d in b.split()] for b in B.splitlines()]
c = [[int(d) for d in c.split()] for c in C.splitlines()]


# Testing No of Differences between of the matrices
noOfDifferentElements(a,b)
noOfDifferentElements(b,c)
noOfDifferentElements(a,c)
and the winner is :
No of Differece Matrix1 & Matrix2 : 10.0
No of Differece Matrix1 & Matrix2 : 10.0
No of Differece Matrix1 & Matrix2 : 4.0
Reply


Messages In This Thread
RE: Partial "visual" Matching of matrices - by masteripper - Nov-03-2019, 05:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  partial functions before knowing the values mikisDeWitte 4 601 Dec-24-2023, 10:00 AM
Last Post: perfringo
  Move Files based on partial Match mohamedsalih12 2 819 Sep-20-2023, 07:38 PM
Last Post: snippsat
  Partial KEY search in dict klatlap 6 1,269 Mar-28-2023, 07:24 AM
Last Post: buran
  remove partial duplicates from csv ledgreve 0 787 Dec-12-2022, 04:21 PM
Last Post: ledgreve
  Webhook, post_data, GPIO partial changes DigitalID 2 991 Nov-10-2022, 09:50 PM
Last Post: deanhystad
  4D matrices ali1almakhmari 0 757 Jun-13-2022, 09:21 AM
Last Post: ali1almakhmari
  Optimal way to search partial correspondence in a large dict genny92c 0 1,001 Apr-22-2022, 10:20 AM
Last Post: genny92c
  Unable to use Pauli Matrices in QNET Package Rupayan 2 1,910 Sep-25-2021, 06:02 AM
Last Post: Rupayan
  Partial Matching Rows In Pandas DataFrame Query eddywinch82 1 2,369 Jul-08-2021, 06:32 PM
Last Post: eddywinch82
  Partial key lookup in dictionary GaryNR 1 3,450 Jul-16-2020, 06:55 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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