Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to find the largest contiguous, overlapping region in a set of sorted arrays
    primarykey
    data
    text
    <p>Given a tuple of ordered 1D-arrays <code>(arr1, arr2, arr3, )</code>, which would be the best way to get a tuple of min/max indices <code>((min1, max1), (min2, max2), (min3, max3), )</code> so that the arrays span the largest common range? </p> <p>What I mean is that </p> <pre><code>min(arr[min1], arr2[min2], arr3[min3]) &gt; max(arr1[min1-1], arr2[min2-1], arr3[min3-1]) </code></pre> <p>and </p> <pre><code>max(arr[min1], arr2[min2], arr3[min3]) &lt; min(arr1[min1+1], arr2[min2+1], arr3[min3+1]) </code></pre> <p>the same for the upper bounds?</p> <p>An example:</p> <p>Given <code>arange(12)</code> and <code>arange(3, 8)</code>, I want to get <code>((3,8), (0,6))</code>, with the goal that <code>arange(12)[3:8] == arange(3,8)[0:6]</code>.</p> <p><strong>EDIT</strong> Note that the arrays can be float or integer.</p> <p>Sorry if this is confusing; I cannot find easier words right now. Any help is greatly appreciated!</p> <p><strong>EDIT2 / answer</strong> I just realize that I was terrible at formulating my question. I ended up solving what I wanted like this:</p> <pre><code> 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) </code></pre> <p>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?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload