Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9164287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:38:46+00:00 2026-06-17T14:38:46+00:00

Given a tuple of ordered 1D-arrays (arr1, arr2, arr3, ) , which would be

  • 0

Given a tuple of ordered 1D-arrays (arr1, arr2, arr3, ), which would be the best way to get a tuple of min/max indices ((min1, max1), (min2, max2), (min3, max3), ) so that the arrays span the largest common range?

What I mean is that

min(arr[min1], arr2[min2], arr3[min3]) > max(arr1[min1-1], arr2[min2-1], arr3[min3-1])

and

max(arr[min1], arr2[min2], arr3[min3]) < min(arr1[min1+1], arr2[min2+1], arr3[min3+1])

the same for the upper bounds?

An example:

Given arange(12) and arange(3, 8), I want to get ((3,8), (0,6)), with the goal that arange(12)[3:8] == arange(3,8)[0:6].

EDIT Note that the arrays can be float or integer.

Sorry if this is confusing; I cannot find easier words right now. Any help is greatly appreciated!

EDIT2 / answer I just realize that I was terrible at formulating my question. I ended up solving what I wanted like this:

 mins = [np.min(t) for t in arrays]
 maxs = [np.max(t) for t in arrays]
 lower_bound = np.max(mins)
 upper_bound = np.min(maxs)
 lower_row = [np.searchsorted(arr, lower_bound, side='left') for arr in arrays]
 upper_row = [np.searchsorted(arr, upper_bound, side='right') for arr in arrays]
 result = zip(lower_row, upper_row)

However, both answers seem to be valid for the question I asked, so I’m unsure to select only one of them as ‘correct’ – what should I do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:38:47+00:00Added an answer on June 17, 2026 at 2:38 pm

    I’m sure there are different ways to do this, I would use a merge algorithm to walk through the two arrays, keeping track of overlap regions. If you’re not familiar with the idea take a look at merge-sort, hopefully between that and the code it’s clear how this works.

    def find_overlap(a, b):
        i = 0
        j = 0
        len_a = len(a)
        len_b = len(b)
        in_overlap = False
        best_count = 0
        best_start = (-1, -1)
        best_end = (-1, -1)
    
        while i < len_a and j < len_b:
    
            if a[i] == b[j]:
                if in_overlap:
                    # Keep track of the length of the overlapping region
                    count += 1
                else:
                    # This is a new overlapping region, set count to 1 record start
                    in_overlap = True
                    count = 1
                    start = (i, j)
                # Step indicies
                i += 1
                j += 1
                end = (i, j)
                if count > best_count:
                    # Is this the longest overlapping region so far?
                    best_count = count
                    best_start = start
                    best_end = end
            # If not in a an overlapping region, only step one index
            elif a[i] < b[j]:
                in_overlap = False
                i += 1
            elif b[j] < a[i]:
                in_overlap = False
                j += 1
            else:
                # This should never happen
                raise
        # End of loop
    
        return best_start, best_end
    

    Note that end here is returned in python convention so that if a=[0, 1, 2] and b=[0, 1, 4], start=(0, 0) and end=(2, 2).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I get a tuple/list element given a condition in python? This occurs
Given a tuple list, i can find the max of the 1st element in
I've made a small function which, given a tuple, compares if all elements in
Given a tuple (specifically, a functions varargs), I want to prepend a list containing
The Python datetime.isocalendar() method returns a tuple (ISO_year, ISO_week_number, ISO_weekday) for the given datetime
Given a set of tuple classes in an OOP language: Pair, Triple and Quad,
I need to get the index of a Tuple<string,string,string,string> in a List with three
I would like to test a function with a tuple from a set of
Given a tuple with elements of type A and another type parametrised in A
Given a list of tuples, where each tuple represents a row in a table,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.