code: def _bin_edges(sample, bins=None, range=None):
      """Create edge arrays"""
      Dlen, Ndim = sample.shape
  
      nbin = np.empty(Ndim, int)  # Number of bins in each dimension
      edges = Ndim * [None]  # Bin edges for each dim (will be 2D array)
      dedges = Ndim * [None]  # Spacing between edges (will be 2D array)
  
      # Select range for each dimension
      # Used only if number of bins is given.
      if range is None:
          smin = np.atleast_1d(np.array(sample.min(axis=0), float))
          smax = np.atleast_1d(np.array(sample.max(axis=0), float))
      else:
          if len(range) != Ndim:
              raise ValueError(
                  f"range given for {len(range)} dimensions; {Ndim} required"
              )
          smin = np.empty(Ndim)
          smax = np.empty(Ndim)
          for i in builtins.range(Ndim):
              if range[i][1] < range[i][0]:
                  raise ValueError(
                      "In {}range, start must be <= stop".format(
                          f"dimension {i + 1} of " if Ndim > 1 else ""
                      )
                  )
              smin[i], smax[i] = range[i]
  
      # Make sure the bins have a finite width.
      for i in builtins.range(len(smin)):
          if smin[i] == smax[i]:
              smin[i] = smin[i] - 0.5
              smax[i] = smax[i] + 0.5
  
      # Preserve sample floating point precision in bin edges
      edges_dtype = (
          sample.dtype
          if np.issubdtype(sample.dtype, np.floating)
          else float
      )
  
      # Create edge arrays
      for i in builtins.range(Ndim):
          if np.isscalar(bins[i]):
              nbin[i] = bins[i] + 2  # +2 for outlier bins
              edges[i] = np.linspace(
                  smin[i], smax[i], nbin[i] - 1, dtype=edges_dtype
              )
          else:
              edges[i] = np.asarray(bins[i], edges_dtype)
              nbin[i] = len(edges[i]) + 1  # +1 for outlier bins
          dedges[i] = np.diff(edges[i])
  
      nbin = np.asarray(nbin)
  
      return nbin, edges, dedges
  
file_path: catboost/contrib/python/scipy/py3/scipy/stats/_binned_statistic.py
imports: import builtins
  import numpy
  from numpy.testing import suppress_warnings
  from operator import index
  from collections import namedtuple
label_desc: Use image node_id 6 for calling a global function with example usage: _bin_edges(sample, bins, range) and returns: nbin,  edges,  dedges