def velocity_confidence(data, vkey='<STR_LIT>', copy=False):
adata = data.copy() if copy else data<EOL>if vkey not in adata.layers.keys():<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>')<EOL><DEDENT>idx = np.array(adata.var[vkey + '<STR_LIT>'].values, dtype=bool)<EOL>X, V = adata.layers['<STR_LIT>'][:, idx].copy(), adata.layers[vkey][:, idx].copy()<EOL>indices = get_indices(dist=adata.uns['<STR_LIT>']['<STR_LIT>'])[<NUM_LIT:0>]<EOL>V -= V.mean(<NUM_LIT:1>)[:, None]<EOL>V_norm = norm(V)<EOL>R = np.zeros(adata.n_obs)<EOL>for i in range(adata.n_obs):<EOL><INDENT>Vi_neighs = V[indices[i]]<EOL>Vi_neighs -= Vi_neighs.mean(<NUM_LIT:1>)[:, None]<EOL>R[i] = np.mean(np.einsum('<STR_LIT>', Vi_neighs, V[i]) / (norm(Vi_neighs) * V_norm[i])[None, :])<EOL><DEDENT>adata.obs[vkey + '<STR_LIT>'] = V_norm.round(<NUM_LIT:2>)<EOL>adata.obs[vkey + '<STR_LIT>'] = R<EOL>logg.hint('<STR_LIT>' + vkey + '<STR_LIT>')<EOL>if vkey + '<STR_LIT>' not in adata.obs.keys():<EOL><INDENT>velocity_confidence_transition(adata, vkey)<EOL><DEDENT>return adata if copy else None<EOL>
Computes confidences of velocities.

    Arguments
    ---------
    data: :class:`~anndata.AnnData`
        Annotated data matrix.
    vkey: `str` (default: `'velocity'`)
        Name of velocity estimates to be used.
    copy: `bool` (default: `False`)
        Return a copy instead of writing to adata.

    Returns
    -------
    Returns or updates `adata` with the attributes
    velocity_length: `.obs`
        Length of the velocity vectors for each individual cell
    velocity_confidence: `.obs`
        Confidence for each cell