code: def compute_membership_strengths(
      knn_indices,
      knn_dists,
      sigmas,
      rhos,
      return_dists=False,
      bipartite=False,
  ):
      """Construct the membership strength data for the 1-skeleton of each local
      fuzzy simplicial set -- this is formed as a sparse matrix where each row is
      a local fuzzy simplicial set, with a membership strength for the
      1-simplex to each other data point.
  
      Parameters
      ----------
      knn_indices: array of shape (n_samples, n_neighbors)
          The indices on the ``n_neighbors`` closest points in the dataset.
  
      knn_dists: array of shape (n_samples, n_neighbors)
          The distances to the ``n_neighbors`` closest points in the dataset.
  
      sigmas: array of shape(n_samples)
          The normalization factor derived from the metric tensor approximation.
  
      rhos: array of shape(n_samples)
          The local connectivity adjustment.
  
      return_dists: bool (optional, default False)
          Whether to return the pairwise distance associated with each edge.
  
      bipartite: bool (optional, default False)
          Does the nearest neighbour set represent a bipartite graph? That is, are the
          nearest neighbour indices from the same point set as the row indices?
  
      Returns
      -------
      rows: array of shape (n_samples * n_neighbors)
          Row data for the resulting sparse matrix (coo format)
  
      cols: array of shape (n_samples * n_neighbors)
          Column data for the resulting sparse matrix (coo format)
  
      vals: array of shape (n_samples * n_neighbors)
          Entries for the resulting sparse matrix (coo format)
  
      dists: array of shape (n_samples * n_neighbors)
          Distance associated with each entry in the resulting sparse matrix
      """
      n_samples = knn_indices.shape[0]
      n_neighbors = knn_indices.shape[1]
  
      rows = np.zeros(knn_indices.size, dtype=np.int32)
      cols = np.zeros(knn_indices.size, dtype=np.int32)
      vals = np.zeros(knn_indices.size, dtype=np.float32)
      if return_dists:
          dists = np.zeros(knn_indices.size, dtype=np.float32)
      else:
          dists = None
  
      for i in range(n_samples):
          for j in range(n_neighbors):
              if knn_indices[i, j] == -1:
                  continue  # We didn't get the full knn for i
              # If applied to an adjacency matrix points shouldn't be similar to themselves.
              # If applied to an incidence matrix (or bipartite) then the row and column indices are different.
              if (bipartite == False) & (knn_indices[i, j] == i):
                  val = 0.0
              elif knn_dists[i, j] - rhos[i] <= 0.0 or sigmas[i] == 0.0:
                  val = 1.0
              else:
                  val = np.exp(
                      -((knn_dists[i, j] - rhos[i]) / (sigmas[i]))
                  )
  
              rows[i * n_neighbors + j] = i
              cols[i * n_neighbors + j] = knn_indices[i, j]
              vals[i * n_neighbors + j] = val
              if return_dists:
                  dists[i * n_neighbors + j] = knn_dists[i, j]
  
      return rows, cols, vals, dists
  
imports: from __future__ import print_function
  import locale
  from warnings import warn
  import time
  from scipy.optimize import curve_fit
  from sklearn.base import BaseEstimator
  from sklearn.utils import check_random_state, check_array
  from sklearn.utils.validation import check_is_fitted
  from sklearn.metrics import pairwise_distances
  from sklearn.preprocessing import normalize
  from sklearn.neighbors import KDTree
  from sklearn.decomposition import PCA, TruncatedSVD
  import numpy
  import scipy.sparse
  from scipy.sparse import tril, triu
  import scipy.sparse.csgraph
  import numba
  import umap.distances
  import umap.sparse
  from umap.utils import submatrix, ts, csr_unique, fast_knn_indices
  from umap.spectral import spectral_layout, tswspectral_layout
  from umap.layouts import optimize_layout_euclidean, optimize_layout_generic, optimize_layout_inverse
  from pynndescent import NNDescent
  from pynndescent.distances import named_distances
  from pynndescent.sparse import sparse_named_distances
label_desc: Use image node_id 7 for calling a global function with example usage: compute_membership_strengths(knn_indices, knn_dists, sigmas, rhos, return_dists, bipartite) and returns: rows,  cols,  vals,  dists