0

I wat to search for indices of an array in two other arrays and want to find out where they match. Firstly, I have a variable which says how many points will be matched It is called brk. This brk equals the length of my search array (searched). In my simple case brk = 2 which means I will have 4 match points (brk * 2). So, I must split my search arry into brk halves and then search each half in each main array (main_x_arr and main_y_arr). I have always one search array and two main arrays, but brk changes and says ho to search for indices. At the moment I am creating each match manually but I am trying to create matches auromatically. This is my code:

searched=np.array([[1., 2.], [-3., 1.]])
brk=len(searched)
main_y_arr=np.array([[1., 5.], [8., 3.], [-3., 8.], [2., 4.]])
main_x_arr=np.array([[1., 7.], [-3., 1.], [4., 7.], [2., 4.]])
match1= np.min (np.unique (np.where((main_y_arr==searched[:int (len(searched)/2)].reshape (-1,1)[:,None]).any(-1))[1]))
match2= np.max (np.unique (np.where((main_x_arr==searched[:int (len(searched)/2):].reshape (-1,1)[:,None]).any(-1))[1]))
match3= np.min (np.unique (np.where((main_y_arr==searched[int (len(searched)/2):].reshape (-1,1)[:,None]).any(-1))[1]))
match4= np.max (np.unique (np.where((main_x_arr==searched[int (len(searched)/2):].reshape (-1,1)[:,None]).any(-1))[1]))

As it can be seen, I am creating each match but I want to find a way to firstly kno I will have 2 * brk matches. Then, split searched array into the number of brk and after that search for each split in each array which makes 4 matches. If the length of my searched array equals 3, then I will have thre splits and finall 6 (eactly like repeating match1 and match2 for three slices to make 6 matches). Or if it is 1, I will have only 2 matches (exactly like having match1 and match2 for only one single slide) because it cannot be splitted anymore. In advance I do appreciate any help and feedback.

8
  • 1
    can you describe what you are trying to accomplish in a sentence ? I'm mostly guessing here: (something like) I have a list of (x,y)-points [seached] i want to search for in a list of points [main] ... Commented Mar 11, 2021 at 10:08
  • Dear @lwohlhart, Thanks for devoting time to me. in a sentence: finding the indices of searched in my main arrays. But the point is that it is not always simple. Sometimes I need to split searched rray and look for each split separately and find the mathed index. Commented Mar 11, 2021 at 10:11
  • okay, do i understand it correctly that main_x_arr and main_y_arr together define the x and y coordinates of your main-points? So there's are the points [(1,1), (7,5), (-3,8),(1,3), .......] ? If so then I think your life would be easier if you reorganize the declaration of your main points array ( even if it's just for the search ) Commented Mar 11, 2021 at 10:16
  • @lwohlhart, unfortunately they are not x and y coordinates of the points. They are just some numbers. In fact, they are numbers of some points in x and y directions and I want to find the matches between these numbers and numbers stored in searched array. Commented Mar 11, 2021 at 10:21
  • 1
    okay i think we're coming close: the actual question at hand is : can you formulate what makes a match ( mathematically or in words ) Commented Mar 11, 2021 at 10:23

1 Answer 1

1

after a lengthy discussion we decided that this solves the OPs requirements:

matches = []
for current_search in searched:
    current_search_reshaped = current_search.reshape(-1,1,1)
    match_min = np.min(np.unique(np.where((main_y_arr == current_search_reshaped).any(-1))[1]))
    match_max = np.max(np.unique(np.where((main_x_arr == current_search_reshaped).any(-1))[1]))
    matches.append((match_min, match_max))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.