code: def brute(func, ranges, args=(), Ns=20, full_output=0, finish=fmin):
      """Minimize a function over a given range by brute force.
  
      :Parameters:
  
      func -- Function to be optimized
      ranges : tuple
          Tuple where each element is a tuple of parameters
                        or a slice object to be handed to numpy.mgrid
  
      args  -- Extra arguments to function.
      Ns : number
          Default number of samples if not given
      full_output : number
          Nonzero to return evaluation grid.
  
      :Returns: (x0, fval, {grid, Jout})
  
      x0 : ndarray
          Value of arguments giving minimum over the grird
      fval : number
          Function value at minimum
      grid : tuple
          tuple with same length as x0 representing the  evaluation grid
      Jout : ndarray -- Function values over grid:  Jout = func(*grid)
  
      :SeeAlso:
  
        fmin, fmin_powell, fmin_cg,
               fmin_bfgs, fmin_ncg -- multivariate local optimizers
        leastsq -- nonlinear least squares minimizer
  
        fmin_l_bfgs_b, fmin_tnc,
               fmin_cobyla -- constrained multivariate optimizers
  
        anneal, brute -- global optimizers
  
        fminbound, brent, golden, bracket -- local scalar minimizers
  
        fsolve -- n-dimenstional root-finding
  
        brentq, brenth, ridder, bisect, newton -- one-dimensional root-finding
  
        fixed_point -- scalar fixed-point finder
  
      Notes
  
      ------------------
  
      Find the minimum of a function evaluated on a grid given by the tuple ranges.
      """
      N = len(ranges)
      if N > 40:
          raise ValueError(
              "Brute Force not possible with more than 40 variables."
          )
      lrange = list(ranges)
      for k in range(N):
          if type(lrange[k]) is not type(slice(None)):
              if len(lrange[k]) < 3:
                  lrange[k] = tuple(lrange[k]) + (complex(Ns),)
              lrange[k] = slice(*lrange[k])
      if N == 1:
          lrange = lrange[0]
  
      def _scalarfunc(*params):
          params = squeeze(asarray(params))
          return func(params, *args)
  
      vecfunc = vectorize(_scalarfunc)
      grid = mgrid[lrange]
      if N == 1:
          grid = (grid,)
      Jout = vecfunc(*grid)
      Nshape = shape(Jout)
      indx = argmin(Jout.ravel(), axis=-1)
      Nindx = zeros(N, int)
      xmin = zeros(N, float)
      for k in range(N - 1, -1, -1):
          thisN = Nshape[k]
          Nindx[k] = indx % Nshape[k]
          indx = indx / thisN
      for k in range(N):
          xmin[k] = grid[k][tuple(Nindx)]
  
      Jmin = Jout[tuple(Nindx)]
      if N == 1:
          grid = grid[0]
          xmin = xmin[0]
      if isinstance(finish, _Callable):
          vals = finish(func, xmin, args=args, full_output=1, disp=0)
          xmin = vals[0]
          Jmin = vals[1]
          if vals[-1] > 0:
              print("Warning: Final optimization did not succeed")
      if full_output:
          return xmin, Jmin, grid, Jout
      else:
          return xmin
  
imports: import numpy
  from numpy import atleast_1d, eye, mgrid, argmin, zeros, shape, empty, squeeze, isscalar, vectorize, asarray, absolute, sqrt, Inf, asfarray, isinf
  from mystic import linesearch
  from collections.abc import Callable
  import builtins
label_desc: Use image node_id 28 for calling a global function with example usage: brute(func, ranges, args, Ns, full_output, finish) and returns: func, xmin,  Jmin,  grid,  Jout, xmin