def moments(data, n_neighbors=<NUM_LIT:30>, n_pcs=<NUM_LIT:30>, mode='<STR_LIT>', method='<STR_LIT>', metric='<STR_LIT>', use_rep=None,<EOL>recurse_neighbors=False, renormalize=False, copy=False):
adata = data.copy() if copy else data<EOL>if '<STR_LIT>' not in adata.layers.keys() or '<STR_LIT>' not in adata.layers.keys():<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if any([not_yet_normalized(adata.layers[layer]) for layer in {'<STR_LIT>', '<STR_LIT>'}]):<EOL><INDENT>normalize_per_cell(adata)<EOL><DEDENT>if '<STR_LIT>' not in adata.uns.keys() or neighbors_to_be_recomputed(adata, n_neighbors=n_neighbors):<EOL><INDENT>if use_rep is None: use_rep = '<STR_LIT>'<EOL>neighbors(adata, n_neighbors=n_neighbors, use_rep=use_rep, n_pcs=n_pcs, method=method, metric=metric)<EOL><DEDENT>if mode not in adata.uns['<STR_LIT>']:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>logg.info('<STR_LIT>' + str(mode), r=True)<EOL>connectivities = get_connectivities(adata, mode, n_neighbors=n_neighbors, recurse_neighbors=recurse_neighbors)<EOL>adata.layers['<STR_LIT>'] = csr_matrix.dot(connectivities, csr_matrix(adata.layers['<STR_LIT>'])).astype(np.float32).A<EOL>adata.layers['<STR_LIT>'] = csr_matrix.dot(connectivities, csr_matrix(adata.layers['<STR_LIT>'])).astype(np.float32).A<EOL>if renormalize: normalize_per_cell(adata, layers={'<STR_LIT>', '<STR_LIT>'}, enforce=True)<EOL>logg.info('<STR_LIT>', time=True, end='<STR_LIT:U+0020>' if settings.verbosity > <NUM_LIT:2> else '<STR_LIT:\n>')<EOL>logg.hint(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL>return adata if copy else None<EOL>
Computes moments for velocity estimation.

    Arguments
    ---------
    data: :class:`~anndata.AnnData`
        Annotated data matrix.
    n_neighbors: `int` (default: 30)
        Number of neighbors to use.
    n_pcs: `int` (default: 30)
        Number of principal components to use.
    mode: `'connectivities'` or `'distances'`  (default: `'connectivities'`)
        Distance metric to use for moment computation.
    renormalize: `bool` (default: `False`)
        Renormalize the moments by total counts per cell to its median.
    copy: `bool` (default: `False`)
        Return a copy instead of writing to adata.

    Returns
    -------
    Returns or updates `adata` with the attributes
    Ms: `.layers`
        dense matrix with first order moments of spliced counts.
    Mu: `.layers`
        dense matrix with first order moments of unspliced counts.