Python Forum
Partial "visual" Matching of matrices - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Partial "visual" Matching of matrices (/thread-22153.html)

Pages: 1 2


Partial "visual" Matching of matrices - masteripper - Nov-01-2019

Hello,
I have this issue and i am a bit short on ideas on how to resolve it
Suppose you have 3 matrices :
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

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

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
At first forget everything about algebra ... i am not after getting any value/solution/simplification what so ever...the deal here is to find the best "visual" match...in this case Matrix A is more matching to Matrix C in comparison to B.
The important thing that no change in order/values should take place...the matrices will remain unaffected no matter what but i need to find that Matrix A differs only to 4 elements compared to C and compared to B differs in 10 elements so the best match is C
P.S. sorry for the bad format of the matrices... i tried to find an appropriate bbcode to format them but no luck


RE: Partial "visual" Matching of matrices - Gribouillis - Nov-01-2019

What exactly is the question?


RE: Partial "visual" Matching of matrices - masteripper - Nov-01-2019

How to find the match

Well i think i might have an idea...
I will subtract the matrices and count the values different to zero.... hmmm...maybe i will try that....


RE: Partial "visual" Matching of matrices - Gribouillis - Nov-01-2019

The obvious idea is to count the entries that differ, but an efficient implementation may depend crucially on the data structure that you have in memory. How do the matrices appear in your program?


RE: Partial "visual" Matching of matrices - masteripper - Nov-01-2019

Exactly as you see them..


RE: Partial "visual" Matching of matrices - Gribouillis - Nov-01-2019

masteripper Wrote:Exactly as you see them..
This is not possible because it is not python code. Post the code and what you've tried to solve the problem.


RE: Partial "visual" Matching of matrices - DeaD_EyE - Nov-01-2019

The answer is C.
C has more equal elements with A as B with A.

I solved it with a nested loop, but you can also serialize the matrix with itertools.chain.from_iterable().
You need zip to get from matrix1 and matrix2 for each iteration two elements.


RE: Partial "visual" Matching of matrices - masteripper - Nov-01-2019

(Nov-01-2019, 12:54 PM)DeaD_EyE Wrote: The answer is C.
C has more equal elements with A as B with A.

I solved it with a nested loop, but you can also serialize the matrix with itertools.chain.from_iterable().
You need zip to get from matrix1 and matrix2 for each iteration two elements.

Thanks man..can you give me some more code

(Nov-01-2019, 12:16 PM)Gribouillis Wrote:
masteripper Wrote:Exactly as you see them..
This is not possible because it is not python code. Post the code and what you've tried to solve the problem.

If i had the concept i could have code it....this is not issue in most cases...but the thing was to grasp the concept...the subtraction is one way... if something better comes it will be great.... (i really didn't thought about subtraction until i posted the thread and i was looking...for start the data are inside pandas dataframes so i have found out that i can subtract them )


RE: Partial "visual" Matching of matrices - newbieAuggie2019 - Nov-01-2019

(Nov-01-2019, 10:22 AM)masteripper Wrote: Suppose you have 3 matrices :
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

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

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

[ ... ] in this case Matrix A is more matching to Matrix C in comparison to B.

Hi!

My approach would be comparing matrix A and matrix B, element by element, and keep the number of elements in common in a variable, named, let's say commonElementsAB.

Then, I would do the same, comparing matrix A and matrix C, element by element, and keep the number of elements in common in a variable, named, let's say commonElementsAC.

After that, I would compare the value of commonElementsAB with the value of commonElementsAC. If the value of commonElementsAB is greater than the value of commonElementsAC, that means that Matrix A is more matching to Matrix B than to Matrix C. If the value of commonElementsAC is greater than the value of commonElementsAB, that means that Matrix A is more matching to Matrix C than to Matrix B.

All the best,


RE: Partial "visual" Matching of matrices - masteripper - Nov-01-2019

(Nov-01-2019, 08:33 PM)newbieAuggie2019 Wrote:
(Nov-01-2019, 10:22 AM)masteripper Wrote: Suppose you have 3 matrices :
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

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

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

[ ... ] in this case Matrix A is more matching to Matrix C in comparison to B.

Hi!

My approach would be comparing matrix A and matrix B, element by element, and keep the number of elements in common in a variable, named, let's say commonElementsAB.

Then, I would do the same, comparing matrix A and matrix C, element by element, and keep the number of elements in common in a variable, named, let's say commonElementsAC.

After that, I would compare the value of commonElementsAB with the value of commonElementsAC. If the value of commonElementsAB is greater than the value of commonElementsAC, that means that Matrix A is more matching to Matrix B than to Matrix C. If the value of commonElementsAC is greater than the value of commonElementsAB, that means that Matrix A is more matching to Matrix C than to Matrix B.

All the best,
I am thinking that this might be slower...but thanks for replying.