code: def fmin_powell(
      func,
      x0,
      args=(),
      xtol=1e-4,
      ftol=1e-4,
      maxiter=None,
      maxfun=None,
      full_output=0,
      disp=1,
      retall=0,
      callback=None,
      direc=None,
  ):
      """Minimize a function using modified Powell's method.
  
      :Parameters:
  
        func -- the Python function or method to be minimized.
        x0 : ndarray
          the initial guess.
        args -- extra arguments for func
        callback -- an optional user-supplied function to call after each
                    iteration.  It is called as callback(xk), where xk is the
                    current parameter vector
        direc -- initial direction set
  
      :Returns: (xopt, {fopt, xi, direc, iter, funcalls, warnflag}, {allvecs})
  
        xopt : ndarray
          minimizer of function
  
        fopt : number
          value of function at minimum: fopt = func(xopt)
        direc -- current direction set
        iter : number
          number of iterations
        funcalls : number
          number of function calls
        warnflag : number
          Integer warning flag:
                    1 : 'Maximum number of function evaluations.'
                    2 : 'Maximum number of iterations.'
        allvecs : Python list
          a list of solutions at each iteration
  
      :OtherParameters:
  
        xtol : number
          line-search error tolerance.
        ftol : number
          acceptable relative error in func(xopt) for convergence.
        maxiter : number
          the maximum number of iterations to perform.
        maxfun : number
          the maximum number of function evaluations.
        full_output : number
          non-zero if fval and warnflag outputs are desired.
        disp : number
          non-zero to print convergence messages.
        retall : number
          non-zero to return a list of the solution at each iteration
  
      :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
  
      -----------------------
  
        Uses a modification of Powell's method to find the minimum of a function
        of N variables
      """
      # we need to use a mutable object here that we can update in the
      # wrapper function
      fcalls, func = wrap_function(func, args)
      x = asarray(x0).flatten()
      if retall:
          allvecs = [x]
      N = len(x)
      rank = len(x.shape)
      if not -1 < rank < 2:
          raise ValueError(
              "Initial guess must be a scalar or rank-1 sequence."
          )
      if maxiter is None:
          maxiter = N * 1000
      if maxfun is None:
          maxfun = N * 1000
  
      if direc is None:
          direc = eye(N, dtype=float)
      else:
          direc = asarray(direc, dtype=float)
  
      fval = squeeze(func(x))
      x1 = x.copy()
      iter = 0
      ilist = range(N)
      while True:
          fx = fval
          bigind = 0
          delta = 0.0
          for i in ilist:
              direc1 = direc[i]
              fx2 = fval
              fval, x, direc1 = _linesearch_powell(
                  func, x, direc1, tol=xtol * 100
              )
              if (fx2 - fval) > delta:
                  delta = fx2 - fval
                  bigind = i
          iter += 1
          if callback is not None:
              callback(x)
          if retall:
              allvecs.append(x)
          if 2.0 * (fx - fval) <= ftol * (abs(fx) + abs(fval)) + 1e-20:
              break
          if fcalls[0] >= maxfun:
              break
          if iter >= maxiter:
              break
  
          # Construct the extrapolated point
          direc1 = x - x1
          x2 = 2 * x - x1
          x1 = x.copy()
          fx2 = squeeze(func(x2))
  
          if fx > fx2:
              t = 2.0 * (fx + fx2 - 2.0 * fval)
              temp = fx - fval - delta
              t *= temp * temp
              temp = fx - fx2
              t -= delta * temp * temp
              if t < 0.0:
                  fval, x, direc1 = _linesearch_powell(
                      func, x, direc1, tol=xtol * 100
                  )
                  direc[bigind] = direc[-1]
                  direc[-1] = direc1
  
      warnflag = 0
      if fcalls[0] >= maxfun:
          warnflag = 1
          if disp:
              print(
                  "Warning: Maximum number of function evaluations has "
                  "been exceeded."
              )
      elif iter >= maxiter:
          warnflag = 2
          if disp:
              print(
                  "Warning: Maximum number of iterations has been exceeded"
              )
      else:
          if disp:
              print("Optimization terminated successfully.")
              print("         Current function value: %s" % fval)
              print("         Iterations: %d" % iter)
              print("         Function evaluations: %d" % fcalls[0])
  
      x = squeeze(x)
  
      if full_output:
          retlist = x, fval, direc, iter, fcalls[0], warnflag
          if retall:
              retlist += (allvecs,)
      else:
          retlist = x
          if retall:
              retlist = (x, allvecs)
  
      return retlist
  
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 26 for calling a global function with example usage: fmin_powell(func, x0, args, xtol, ftol, maxiter, maxfun, full_output, disp, retall, callback, direc) and returns: retlist