Nov-03-2019, 05:41 PM
(This post was last modified: Nov-03-2019, 05:41 PM by masteripper.)
Well thanks for the responses
With your help i have constructed the following (Pandas is great !!! )
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