<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 11 October 2017 at 19:01, Antonio Polino <span dir="ltr"><<a href="mailto:antoniy.py@gmail.com" target="_blank">antoniy.py@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">



<div>
<div name="messageBodySection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif">On the other hand, the array A is always the same, only k changes. So it would be beneficial to use some auxiliary structure (like a "inverse KDTree") on A, and then query the results on the small array k. </div></div></blockquote><div><br></div><div>You can sort A and use searchsorted to find the positions of the midpoints of k. Then, you assign the values to the group.</div><div><br></div><div>In your example (adding one more and sorting k):</div><div><div><br></div>
<div>    >>> A = np.asarray([3, 4, 5, 6])</div>
<div>    >>> k = np.asarray([3, 4.1, 5.2])</div><div>    >>> midpoints = np.array([ 3.55,  4.65])   #  k[:-1] + np.diff(k) / 2 <br></div><div>    >>> np.searchsorted(A, midpoints)<br>    array([1, 2])<br></div><div><br></div><div>So, this means that A[:1] belong to k[0], A[1:2] belong to k[2] and A[2:] belong to k[3]</div><div><br></div><div><br></div><div>/David.</div><div><br></div><div>PS: in your later email I see your name as Ant.<br></div></div></div></div></div>