code: def clamp(x, bins, mask=None):
      """
      Clamp array values that fall within a given mask in the range
      [0..bins-1] and reset masked values to -1.
  
      Parameters
      ----------
      x : ndarray
        The input array
      bins : number
        Desired number of bins
      mask : ndarray, tuple or slice
        Anything such that x[mask] is an array.
  
      Returns
      -------
      y : ndarray
        Clamped array, masked items are assigned -1
      bins : number
        Adjusted number of bins
      """
      if bins > np.iinfo(np.short).max:
          raise ValueError("Too large a bin size")
      y = -np.ones(x.shape, dtype=CLAMP_DTYPE)
      if mask is None:
          y, bins = _clamp(x, y, bins)
      else:
          ym = y[mask]
          xm = x[mask]
          ym, bins = _clamp(xm, ym, bins)
          y[mask] = ym
      return y, bins
  
imports: import numpy
  import scipy.ndimage
  from ...core.image.image_spaces import as_xyz_image, make_xyz_image, xyz_affine
  from ._registration import _joint_histogram
  from .affine import affine_transforms, inverse_affine, subgrid_affine
  from .chain_transform import ChainTransform
  from .optimizer import configure_optimizer
  from .similarity_measures import similarity_measures
label_desc: Use image node_id 2 for calling a global function with example usage: clamp(x, bins, mask) and returns: y,  bins