- navis.geodesic_matrix(x, from_=None, directed=False, weight='weight', limit=inf)¶
Generate geodesic (“along-the-arbor”) distance matrix between nodes/vertices.
from (list | numpy.ndarray, optional) – Node IDs (for TreeNeurons) or vertex indices (for MeshNeurons). If provided, will compute distances only FROM this subset to all other nodes/vertices.
directed (bool, optional) – If True, pairs without a child->parent path will be returned with
distance = "inf". Only relevant for
weight ('weight' | None, optional) – If
weightdistances are given as physical length. If
Nonedistances is number of nodes.
limit (int | float, optional) – Use to limit distance calculations. Nodes that are not within
limitwill have distance
np.inf. If neuron has its .units set, you can also pass a string such as “10 microns”.
Geodesic distance matrix. Distances in nanometres.
- Return type:
Find average geodesic distance between all leaf nodes
>>> import navis >>> n = navis.example_neurons(1) >>> # Generate distance matrix >>> m = navis.geodesic_matrix(n) >>> # Subset matrix to leaf nodes >>> leafs = n.nodes[n.nodes.type=='end'].node_id.values >>> l_dist = m.loc[leafs, leafs] >>> # Get mean >>> round(l_dist.mean().mean()) 12983