code: def _compute_weights_3d(data, spacing, beta, eps, multichannel):
      # Weight calculation is main difference in multispectral version
      # Original gradient**2 replaced with sum of gradients ** 2
      gradients = (
          np.concatenate(
              [
                  np.diff(data[..., 0], axis=ax).ravel() / spacing[ax]
                  for ax in [2, 1, 0]
                  if data.shape[ax] > 1
              ],
              axis=0,
          )
          ** 2
      )
      for channel in range(1, data.shape[-1]):
          gradients += (
              np.concatenate(
                  [
                      np.diff(data[..., channel], axis=ax).ravel()
                      / spacing[ax]
                      for ax in [2, 1, 0]
                      if data.shape[ax] > 1
                  ],
                  axis=0,
              )
              ** 2
          )
  
      # All channels considered together in this standard deviation
      scale_factor = -beta / (10 * data.std())
      if multichannel:
          # New final term in beta to give == results in trivial case where
          # multiple identical spectra are passed.
          scale_factor /= np.sqrt(data.shape[-1])
      weights = np.exp(scale_factor * gradients)
      weights += eps
      return -weights
  
file_path: scikit-image/skimage/segmentation/random_walker_segmentation.py
imports: import numpy
  from scipy import sparse, ndimage
  from .._shared import utils
  from .._shared.utils import warn
  from ..util import img_as_float
  from scipy.sparse.linalg import cg, spsolve
label_desc: Use image node_id 2 for calling a global function with example usage: _compute_weights_3d(data, spacing, beta, eps, multichannel) and returns: unknown