code: def _fprime(x, fx, method=None, extrap=False, **kwds):
      """find gradient of ``fx`` at ``x``, with ``fx`` a function ``z = fx(x)``
  
      Args:
        x (ndarray): an array of shape ``(npts, dim)`` or ``(npts,)``
        fx (function): a function of form ``z = fx(x)``
        method (str, default=None): string name of the kind of gradient method
        extrap (bool, default=False): if True, extrapolate a bounding box
        new (bool, default=False): include the extrapolated points in the output
  
      Returns:
        array of dimensions ``x.shape``, gradient of the points at ``(x,fx)``
  
      Notes:
        - if method is ``'approx'`` (the default), use ``approx_fprime`` from
          ``mystic``, which uses a local gradient approximation; other choices
          are ``'symbolic'``, which uses ``mpmath.diff`` if installed.
        - if ``extrap`` is True, extrapolate using ``interpf`` with
          ``method='thin_plate'`` (or ``'rbf'`` if ``scipy`` is not installed).
          Alternately, any one of ``('rbf', 'linear', 'cubic', 'nearest',
          'inverse', 'gaussian', 'multiquadric', 'quintic', 'thin_plate')`` can
          be used. If ``extrap`` is a cost function ``z = f(x)``, then directly
          use it in the extrapolation. Using extrapolation can reduce the number
          of ``nan``.
      """
      slc = (
          slice(None, None)
          if kwds.get("new", False)
          else slice(None, len(x))
      )
      import numpy as np
  
      if extrap:
          x = extrapolate(x)
      x, i = _unique(x, index=True)
      if method is None or method == "approx":
          from mystic._scipyoptimize import approx_fprime, _epsilon
  
          err = np.seterr(
              all="ignore"
          )  # silence warnings (division by nan)
          # fx = _to_objective(fx) # conform to gradient interface
          x, s = np.atleast_2d(x), x.shape
          z = np.array(
              [approx_fprime(xi, fx, _epsilon) for xi in x]
          ).reshape(*s)
          np.seterr(**err)
          return z[i][slc]
      try:  # XXX: mpmath.diff is more error prone -- don't use it?
          from mpmath import diff
      except ImportError:
          return _fprime(x, fx, method=None)[i][slc]
      err = np.seterr(
          all="ignore"
      )  # silence warnings (division by nan)
      # fx = _to_objective(fx) # conform to gradient interface
      k = range(s[-1])
      z = np.array(
          [
              [
                  diff(
                      lambda *x: fx(_swapvals(x, j)),
                      xk[_swapvals(k, j)],
                      (1,),
                  )
                  for j in k
              ]
              for xk in x
          ],
          dtype=x.dtype,
      ).reshape(*s)
      np.seterr(**err)
      return z[i][slc]
  
imports: from mystic.math import _rbf
label_desc: Use image node_id 23 for calling a global function with example usage: _fprime(x, fx, method, extrap) and returns: z, z, _fprime