def distance_submatrix(self, dist_mat): r"""Extract matrix of distances between leafs under the node. Parameters ---------- dist_mat: numpy.ndarray Distance matrix (square or in condensed form) among all N leaves of the tree to which the node belongs to. The row indexes of `dist_mat` must correspond to the node IDs of the leaves. Returns ------- :class:`~numpy:numpy.ndarray` square distance matrix MxM between the M leafs under the node """ return distance_submatrix(dist_mat, self.leaf_ids)
def test_distance_submatrix(): a = np.arange(4) dist_mat = np.square(a - a[:, np.newaxis]) submatrix = idpd.distance_submatrix(dist_mat, [1, 3]) reference = np.array([[0, 4], [4, 0]]) assert_allclose(submatrix, reference, atol=0.001)