def find_dist_to_centroid ( cvects , idx_list , weights = None ) : centroid = find_centroid ( cvects , idx_list , weights ) dist_vals = np . degrees ( np . arccos ( ( centroid * cvects . T [ idx_list ] ) . sum ( 1 ) ) ) return dist_vals , centroid
calculate centroid vector of list of vectors python
Find the centroid for a set of vectors
def find_dist_to_centroid(cvects, idx_list, weights=None):
    """ Find the centroid for a set of vectors

    Parameters
    ----------
    cvects : ~numpy.ndarray(3,nsrc) with directional cosine (i.e., x,y,z component) values

    idx_list : [int,...]
      list of the source indices in the cluster

    weights : ~numpy.ndarray(nsrc) with the weights to use.  None for equal weighting

    returns (np.ndarray(nsrc)) distances to the centroid (in degrees)
    """
    centroid = find_centroid(cvects, idx_list, weights)
    dist_vals = np.degrees(np.arccos((centroid * cvects.T[idx_list]).sum(1)))
    return dist_vals, centroid