Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should be doing things differently anyway. Unfortunatly the <code>cKDTree</code> which is much faster does not have the necessary features, but even the other <code>KDTree</code> should give you a vast speed increase (and solve it much more elegantly)</p> <pre><code>from scipy.spatial import KDTree from itertools import chain tree = KDTree(circles) # unfortunatly only a list of lists, because there may be a different amount # also the point itself is included every time. connections = tree.query_ball_tree(tree, 2*r) # if all you want is a list of lists of what connects with what # connections is already what you need. The rest creates a connectivity matrix: repeats = [len(l) for l in connections] x_point = np.arange(len(circles)).repeat(repeats) y_point = np.fromiter(chain(*connections), dtype=np.intp) # or construct a sparse matrix here instead, scipy.sparse has some graph tools # maybe it even has a better thing to do this. connected = np.zeros((len(circles),) * 2, dtype=bool) connected[x_point, y_point] = True </code></pre> <p>While it doesn't use <code>cKDTree</code> unfortunatly, this still saves you the <code>O(N^2)</code> complexity... Of course if <code>len(circles)</code> is small, that does not matter, but then you can just use broadcasting, (or also <code>distance_matrix</code> from <code>scipy.spatial</code>):</p> <pre><code>distances = np.sqrt(((circles[:,None,:] - circles)**2).sum(-1)) connected = distances &lt; (2 * r) # if you need the list of lists/arrays here you can do: connections = [np.flatnonzero(c) for c in connected] </code></pre> <p>But note that the second method is a memory hungry monster and only any good if <code>circles</code> is small.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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