Note that there are some explanatory texts on larger screens.

plurals
  1. POMore efficient way to count intersections?
    primarykey
    data
    text
    <p>I have a list of 300000 lists (fiber tracks), where each track is a list of (x,y,z) tuples/coordinates:</p> <pre><code>tracks= [[(1,2,3),(3,2,4),...] [(4,2,1),(5,7,3),...] ... ] </code></pre> <p>I also have a group of masks, where each mask is defined as a list of (x,y,z) tuples/coordinates: </p> <pre><code>mask_coords_list= [[(1,2,3),(8,13,4),...] [(6,2,2),(5,7,3),...] ... ] </code></pre> <p>I am trying to find, for all possible pairs of masks:</p> <ol> <li>the number of tracks that intersect each mask-mask pair (to create a connectivity matrix)</li> <li>the subset of tracks that intersect each mask, in order to add 1 to each (x,y,z) coordinate for each track in the subset (to create a "density" image)</li> </ol> <p>I'm currently doing part 1 like so:</p> <pre><code>def mask_connectivity_matrix(tracks,masks,masks_coords_list): connect_mat=zeros((len(masks),len(masks))) for track in tracks: cur=[] for count,mask_coords in enumerate(masks_coords_list): if any(set(track) &amp; set(mask_coords)): cur.append(count) for x,y in list(itertools.combinations(cur,2)): connect_mat[x,y] += 1 </code></pre> <p>and part 2 like so:</p> <pre><code>def mask_tracks(tracks,masks,masks_coords_list): vox_tracks_img=zeros((xdim,ydim,zdim,len(masks))) for track in tracks: for count,mask in enumerate(masks_coords_list): if any(set(track) &amp; set(mask)): for x,y,z in track: vox_tracks_img[x,y,z,count] += 1 </code></pre> <p>Using sets to find intersections has sped this process up significantly but both portions still take over an hour when I have a list of 70 or more masks. Is there a more efficient way to do this than iterating for each track?</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