<div dir="ltr">Hi Antonio,<div><br></div><div>I think yo are looking for the scipy.spatial.distance_matrix function</div><div><br></div><div>I used it inside a wave crest tracking algorithm  (on probably a much smaller matrix than your), but unfortunately, there is no magical method to reduce significantly the computation time.</div><div><br></div><div><br></div><div>Have a go at it</div><div><br></div><div>Xavier</div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-10-12 7:13 GMT+11:00 Daπid <span dir="ltr"><<a href="mailto:davidmenhur@gmail.com" target="_blank">davidmenhur@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="">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></span><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><span class=""><div><br></div>
<div>    >>> A = np.asarray([3, 4, 5, 6])</div>
</span><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>
<br>______________________________<wbr>_________________<br>
SciPy-User mailing list<br>
<a href="mailto:SciPy-User@python.org">SciPy-User@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/scipy-user" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/scipy-user</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"> « Quand le gouvernement viole les droits du peuple, l'insurrection est, pour le peuple et pour chaque portion du peuple, le plus sacré des droits et le plus indispensable des devoirs »<br><br>Déclaration des droits de l'homme et du citoyen, article 35, 1793</div>
</div>