code: def ndbincount(x, weights=None, shape=None):
      """Like bincount, but for nd-indices.
  
      Parameters
      ----------
      x : array_like (N, M)
          M indices to a an Nd-array
      weights : array_like (M,), optional
          Weights associated with indices
      shape : optional
          the shape of the output
      """
      x = np.asarray(x)
      if shape is None:
          shape = x.max(1) + 1
  
      x = np.ravel_multi_index(x, shape)
      out = np.bincount(x, weights, minlength=np.prod(shape))
      out.shape = shape
  
      return out
  
imports: from collections import defaultdict, OrderedDict
  from functools import wraps
  from itertools import combinations, groupby
  from warnings import warn
  import numpy
  from nibabel.affines import apply_affine
  from scipy.spatial.distance import cdist
  from dipy.core.geometry import dist_to_corner
  from dipy.tracking import metrics
  from dipy.tracking.vox2track import _streamlines_in_mask
  from dipy.tracking._utils import _mapping_to_voxel, _to_voxel_coordinates
label_desc: Use image node_id 3 for calling a global function with example usage: ndbincount(x, weights, shape) and returns: out