code: def resistance_distance(G):
      r
  
      if sparse.issparse(G):
          L = G.tocsc()
  
      else:
          if G.lap_type != 'combinatorial':
              raise ValueError('Need a combinatorial Laplacian.')
          L = G.L.tocsc()
  
      try:
          pseudo = sparse.linalg.inv(L)
      except RuntimeError:
          pseudo = sparse.lil_matrix(np.linalg.pinv(L.toarray()))
  
      N = np.shape(L)[0]
      d = sparse.csc_matrix(pseudo.diagonal())
      rd = sparse.kron(d, sparse.csc_matrix(np.ones((N, 1)))).T \
          + sparse.kron(d, sparse.csc_matrix(np.ones((N, 1)))) \
          - pseudo - pseudo.T
  
      return rd
docs: r"""
      Compute the resistance distances of a graph.
  
      Parameters
      ----------
      G : Graph or sparse matrix
          Graph structure or Laplacian matrix (L)
  
      Returns
      -------
      rd : sparse matrix
          distance matrix
  
      References
      ----------
      :cite:`klein1993resistance`