code: def _calc_binned_statistic(
      Vdim, bin_numbers, result, values, stat_func
  ):
      unique_bin_numbers = np.unique(bin_numbers)
      for vv in builtins.range(Vdim):
          bin_map = _create_binned_data(
              bin_numbers, unique_bin_numbers, values, vv
          )
          for i in unique_bin_numbers:
              # if the stat_func is np.std, calc std only when binned data is 2
              # or more for speed up.
              if stat_func == "std":
                  if len(bin_map) >= 2:
                      result[vv, i] = np.std(np.array(bin_map[i]))
              elif stat_func == "median":
                  result[vv, i] = np.median(np.array(bin_map[i]))
              elif stat_func == "min":
                  result[vv, i] = np.min(np.array(bin_map[i]))
              elif stat_func == "max":
                  result[vv, i] = np.max(np.array(bin_map[i]))
              else:
                  raise Exception(
                      "Exception: {stat_func} is not supported"
                  )
  
imports: import numpy
  import builtins
label_desc: Use image node_id 2 for calling a global function with example usage: _calc_binned_statistic(Vdim, bin_numbers, result, values, stat_func) without return types