def dispersion_ranking_NN(self, nnm, num_norm_avg=<NUM_LIT:50>):
self.knn_avg(nnm)<EOL>D_avg = self.adata.layers['<STR_LIT>']<EOL>mu, var = sf.mean_variance_axis(D_avg, axis=<NUM_LIT:0>)<EOL>dispersions = np.zeros(var.size)<EOL>dispersions[mu > <NUM_LIT:0>] = var[mu > <NUM_LIT:0>] / mu[mu > <NUM_LIT:0>]<EOL>self.adata.var['<STR_LIT>'] = dispersions.copy()<EOL>ma = np.sort(dispersions)[-num_norm_avg:].mean()<EOL>dispersions[dispersions >= ma] = ma<EOL>weights = ((dispersions / dispersions.max())**<NUM_LIT:0.5>).flatten()<EOL>self.adata.var['<STR_LIT>'] = weights<EOL>return weights<EOL>
Computes the spatial dispersion factors for each gene.

        Parameters
        ----------
        nnm - scipy.sparse, float
            Square cell-to-cell nearest-neighbor matrix.

        num_norm_avg - int, optional, default 50
            The top 'num_norm_avg' dispersions are averaged to determine the
            normalization factor when calculating the weights. This ensures
            that outlier genes do not significantly skew the weight
            distribution.

        Returns:
        -------
        indices - ndarray, int
            The indices corresponding to the gene weights sorted in decreasing
            order.

        weights - ndarray, float
            The vector of gene weights.