Python Forum
Partial "visual" Matching of matrices
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Partial "visual" Matching of matrices
#1
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
Reply
#2
What exactly is the question?
Reply
#3
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....
Reply
#4
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?
Reply
#5
Exactly as you see them..
Reply
#6
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.
Reply
#7
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.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#8
(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 )
Reply
#9
(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,
newbieAuggie2019

"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
Reply
#10
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  partial functions before knowing the values mikisDeWitte 4 604 Dec-24-2023, 10:00 AM
Last Post: perfringo
  Move Files based on partial Match mohamedsalih12 2 822 Sep-20-2023, 07:38 PM
Last Post: snippsat
  Partial KEY search in dict klatlap 6 1,272 Mar-28-2023, 07:24 AM
Last Post: buran
  remove partial duplicates from csv ledgreve 0 788 Dec-12-2022, 04:21 PM
Last Post: ledgreve
  Webhook, post_data, GPIO partial changes DigitalID 2 994 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,915 Sep-25-2021, 06:02 AM
Last Post: Rupayan
  Partial Matching Rows In Pandas DataFrame Query eddywinch82 1 2,374 Jul-08-2021, 06:32 PM
Last Post: eddywinch82
  Partial key lookup in dictionary GaryNR 1 3,457 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