code: def approximate_taylor_polynomial(f, x, degree, scale, order=None):
      """
      Estimate the Taylor polynomial of f at x by polynomial fitting.
  
      Parameters
      ----------
      f : callable
          The function whose Taylor polynomial is sought. Should accept
          a vector of `x` values.
      x : scalar
          The point at which the polynomial is to be evaluated.
      degree : int
          The degree of the Taylor polynomial
      scale : scalar
          The width of the interval to use to evaluate the Taylor polynomial.
          Function values spread over a range this wide are used to fit the
          polynomial. Must be chosen carefully.
      order : int or None, optional
          The order of the polynomial to be used in the fitting; `f` will be
          evaluated ``order+1`` times. If None, use `degree`.
  
      Returns
      -------
      p : poly1d instance
          The Taylor polynomial (translated to the origin, so that
          for example p(0)=f(x)).
  
      Notes
      -----
      The appropriate choice of "scale" is a trade-off; too large and the
      function differs from its Taylor polynomial too much to get a good
      answer, too small and round-off errors overwhelm the higher-order terms.
      The algorithm used becomes numerically unstable around order 30 even
      under ideal circumstances.
  
      Choosing order somewhat larger than degree may improve the higher-order
      terms.
  
      """
      if order is None:
          order = degree
  
      n = order + 1
      # Choose n points that cluster near the endpoints of the interval in
      # a way that avoids the Runge phenomenon. Ensure, by including the
      # endpoint or not as appropriate, that one point always falls at x
      # exactly.
      xs = scale * np.cos(np.linspace(0, np.pi, n, endpoint=n % 1)) + x
  
      P = KroghInterpolator(xs, f(xs))
      d = P.derivatives(x, der=degree + 1)
  
      return np.poly1d((d / factorial(np.arange(degree + 1)))[::-1])
  
imports: from __future__ import division, print_function, absolute_import
  import warnings
  import numpy
  from scipy.special import factorial
  from scipy._lib.six import xrange
  from scipy._lib._util import _asarray_validated
label_desc: Use image node_id 3 for calling a global function with example usage: approximate_taylor_polynomial(f, x, degree, scale, order) and returns: np