{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {},
  "_ordered_sections": [],
  "item_file": null,
  "item_line": null,
  "item_type": null,
  "aliases": [],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": null,
  "references": null,
  "qa": "tutorial:interpolate:1D",
  "arbitrary": [
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "tutorial-interpolate_1Dsection"
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "1-D interpolation"
        }
      ],
      "level": 0,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If all you need is a linear (a.k.a. broken line) interpolation, you can use the "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.interp",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:interp"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " routine. It takes two arrays of data to interpolate, "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "y"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and a third array, "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "xnew"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", of points to evaluate the interpolation on:"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> import numpy as np\n>>> x = np.linspace(0, 10, num=11)\n>>> y = np.cos(-x**2 / 9.0)\n\nConstruct the interpolation\n\n>>> xnew = np.linspace(0, 10, num=1001)\n>>> ynew = np.interp(xnew, x, y)\n\nAnd plot it\n\n>>> import matplotlib.pyplot as plt\n>>> plt.plot(xnew, ynew, '-', label='linear interp')\n>>> plt.plot(x, y, 'o', label='data')\n>>> plt.legend(loc='best')\n>>> plt.show()",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "One limitation of "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.interp",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:interp"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is that it does not allow controlling the extrapolation. See the "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "interpolation with B-Splines section",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "tutorial:interpolate:1D"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " section for alternative routines which provide this kind of functionality."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Piecewise linear interpolation"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Of course, piecewise linear interpolation produces corners at data points, where linear pieces join. To produce a smoother curve, you can use cubic splines, where the interpolating curve is made of cubic pieces with matching first and second derivatives. In code, these objects are represented via the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "CubicSpline"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " class instances. An instance is constructed with the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "y"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " arrays of data, and then it can be evaluated using the target "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "xnew"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " values:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> from scipy.interpolate import CubicSpline\n>>> spl = CubicSpline([1, 2, 3, 4, 5, 6], [1, 4, 8, 16, 25, 36])\n>>> spl(2.5)\n5.57",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "A "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "CubicSpline",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " object's "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "__call__"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " method accepts both scalar values and arrays. It also accepts a second argument, "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "nu"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", to evaluate the  derivative of order "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "nu"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". As an example, we plot the derivatives of a spline:"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> from scipy.interpolate import CubicSpline\n>>> x = np.linspace(0, 10, num=11)\n>>> y = np.cos(-x**2 / 9.)\n>>> spl = CubicSpline(x, y)\n\n>>> import matplotlib.pyplot as plt\n>>> fig, ax = plt.subplots(4, 1, figsize=(5, 7))\n>>> xnew = np.linspace(0, 10, num=1001)\n>>> ax[0].plot(xnew, spl(xnew))\n>>> ax[0].plot(x, y, 'o', label='data')\n>>> ax[1].plot(xnew, spl(xnew, nu=1), '--', label='1st derivative')\n>>> ax[2].plot(xnew, spl(xnew, nu=2), '--', label='2nd derivative')\n>>> ax[3].plot(xnew, spl(xnew, nu=3), '--', label='3rd derivative')\n>>> for j in range(4):\n...     ax[j].legend(loc='best')\n>>> plt.tight_layout()\n>>> plt.show()",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Note that the first and second derivatives are continuous by construction, and the third derivative jumps at data points."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Cubic splines"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Cubic splines are by construction twice continuously differentiable. This may lead to the spline function oscillating and ''overshooting'' in between the data points. In these situations, an alternative is to use the so-called "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "monotone"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " cubic interpolants: these are constructed to be only once continuously differentiable, and attempt to preserve the local shape implied by the data. "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "scipy.interpolate",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "*",
                "kind": "api",
                "path": "scipy.interpolate"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " provides two objects of this kind: "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "PchipInterpolator",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "Akima1DInterpolator",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " . To illustrate, let's consider data with an outlier:"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> from scipy.interpolate import CubicSpline, PchipInterpolator, Akima1DInterpolator\n>>> x = np.array([1., 2., 3., 4., 4.5, 5., 6., 7., 8])\n>>> y = x**2\n>>> y[4] += 101\n\n>>> import matplotlib.pyplot as plt\n>>> xx = np.linspace(1, 8, 51)\n>>> plt.plot(xx, CubicSpline(x, y)(xx), '--', label='spline')\n>>> plt.plot(xx, Akima1DInterpolator(x, y)(xx), '-', label='Akima1D')\n>>> plt.plot(xx, PchipInterpolator(x, y)(xx), '-', label='pchip')\n>>> plt.plot(x, y, 'o')\n>>> plt.legend()\n>>> plt.show()",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Monotone interpolants"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "B-splines form an alternative (if formally equivalent) representation of piecewise polynomials. This basis is generally more computationally stable than the power basis and is useful for a variety of applications which include interpolation, regression and curve representation. Details are given in the "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "piecewise polynomials section",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "tutorial:interpolate:splines_and_polynomials"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and here we illustrate their usage by constructing the interpolation of a sine function:"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> x = np.linspace(0, 3/2, 7)\n>>> y = np.sin(np.pi*x)\n\nTo construct the interpolating objects given data arrays, ``x`` and ``y``,\nwe use the `make_interp_spline` function:\n\n>>> from scipy.interpolate import make_interp_spline\n>>> bspl = make_interp_spline(x, y, k=3)\n\nThis function returns an object which has an interface similar to that\nof the `CubicSpline` objects.  In particular, it can be evaluated at a data\npoint and differentiated:\n\n>>> der = bspl.derivative()      # a BSpline representing the derivative\n>>> import matplotlib.pyplot as plt\n>>> xx = np.linspace(0, 3/2, 51)\n>>> plt.plot(xx, bspl(xx), '--', label=r'$\\sin(\\pi x)$ approx')\n>>> plt.plot(x, y, 'o', label='data')\n>>> plt.plot(xx, der(xx)/np.pi, '--', label=r'$d \\sin(\\pi x)/dx / \\pi$ approx')\n>>> plt.legend()\n>>> plt.show()",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Note that by specifying "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "k=3"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " in the "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "make_interp_spline",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " call, we requested a cubic spline (this is the default, so "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "k=3"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " could have been omitted); the derivative of a cubic is a quadratic:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> bspl.k, der.k\n(3, 2)",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "By default, the result of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "make_interp_spline(x, y)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is equivalent to "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "CubicSpline(x, y)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The difference is that the former allows several optional capabilities: it can construct splines of various degrees (via the optional argument "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "k"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ") and predefined knots (via the optional argument "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "t"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ")."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Boundary conditions for the spline interpolation can be controlled by the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "bc_type"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " argument to "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "make_interp_spline",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " function and "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "CubicSpline",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " constructor. By default, both use the 'not-a-knot' boundary condition."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Interpolation with B-splines"
        }
      ],
      "level": 1,
      "target": "tutorial-interpolate_bsplines"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "One use of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "make_interp_spline"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is constructing a linear interpolant with linear extrapolation since "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "make_interp_spline"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " extrapolates by default. Consider"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> from scipy.interpolate import make_interp_spline\n>>> x = np.linspace(0, 5, 11)\n>>> y = 2*x\n>>> spl = make_interp_spline(x, y, k=1)  # k=1: linear\n>>> spl([-1, 6])\n[-2., 12.]\n>>> np.interp([-1, 6], x, y)\n[0., 10.]",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "See "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "the extrapolation section",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "tutorial:interpolate:extrapolation_examples"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for more details and discussion."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Non-cubic splines"
        }
      ],
      "level": 2,
      "target": "tutorial-interpolate_linear_spline"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Univariate interpolators accept not only one-dimensional "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "y"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " arrays, but also "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "y.ndim > 1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The interpretation is that "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "y"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is a "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "batch"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " of 1D data arrays: by default, the zeroth dimension of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "y"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is the interpolation axis, and the trailing  dimensions are batch dimensions. Consider a collection (a "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "batch"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ") of functions "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "f_j"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " sampled at the points "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x_i"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". We can instantiate a single interpolator for all of these functions by  providing a two-dimensional array "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "y"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " such that "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "y[i, j]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " records "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "f_j(x_i)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To illustrate:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> import numpy as np\n>>> import matplotlib.pyplot as plt\n>>> from scipy.interpolate import make_interp_spline\n>>> n = 11\n>>> x = 2 * np.pi * np.arange(n) / n\n>>> x.shape\n(11,)\n>>> y = np.stack((np.sin(x)**2, np.cos(x)), axis=1)\n>>> y.shape\n(11, 2)\n>>> spl = make_interp_spline(x, y)\n>>> xv = np.linspace(0, 2*np.pi, 51)\n>>> plt.plot(x, y, 'o')\n>>> plt.plot(xv, spl(xv), '-')\n>>> plt.show()",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Several notes are in order. First and foremost, the behavior here looks similar to NumPy's broadcasting, but differs in two respects:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": true,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "x"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " array is expected to be 1D even if the "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "y"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " array is not: "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "x.ndim == 1"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "    while "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "y.ndim >= 1"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". There is no broadcasting of "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "x"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " vs "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "y"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "By default, the "
                    },
                    {
                      "__type": "Emphasis",
                      "__tag": 4047,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "trailing"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " dimensions are used as batch dimensions, in contrast     to the NumPy convention of using the "
                    },
                    {
                      "__type": "Emphasis",
                      "__tag": 4047,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "leading"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " dimensions as batch dimensions."
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Second, the interpolation axis can be controlled by an optional "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "axis"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " argument. The example above uses the default value of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "axis=0"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". For a non-default values, the following is true:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "y.shape[axis] == x.size"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " (otherwise en error is raised)"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "the shape of "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "spl(xv)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "y.shape[axis:] + xv.shape + y.shape[:axis]"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "While we demonstrated the batching behavior with "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "make_interp_spline",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", in fact the majority of univariate interpolators support this functionality: "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "PchipInterpolator",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "Akima1DInterpolator",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "CubicSpline",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "; low-level polynomial representation classes, "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "PPoly",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "BPoly",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "BSpline",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "; as well as "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "least-squares fit and spline smoothing functions<tutorial-interpolate_fitpack>",
              "domain": null,
              "role": "ref",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "make_lsq_spline",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "make_smoothing_spline",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Batches of "
        },
        {
          "__type": "InlineCode",
          "__tag": 4051,
          "value": "y"
        }
      ],
      "level": 1,
      "target": "tutorial-interpolate_batching"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "So far we considered spline "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "functions"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", where the data, "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "y"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", is expected to depend explicitly on the independent variable "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "---so that the interpolating function satisfies "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "f(x_j) = y_j"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Spline "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "curves"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " treat the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "y"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " arrays as coordinates of points, "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\mathbf{p}_j"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " on a plane, and an interpolating curve which passes through these points is parameterized by some additional parameter (typically called "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "u"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "). Note that this construction readily generalizes to higher dimensions where "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\mathbf{p}_j"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " are points in an N-dimensional space."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Spline curves can be easily constructed using the fact that interpolation functions handle multidimensional data arrays, as discussed in "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "the previous section",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "tutorial:interpolate:1D"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The values of the parameter, "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "u"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", corresponding to the data points, need to be separately supplied by the user."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The choice of parametrization is problem-dependent and different parametrizations may produce vastly different curves. As an example, we consider three parametrizations of (a somewhat difficult) dataset, which we take from Chapter 6 of Ref [1] listed in the "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "BSpline",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " docstring:"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> x = [0, 1, 2, 3, 4, 5, 6]\n>>> y = [0, 0, 0, 9, 0, 0, 0]\n>>> p = np.stack((x, y))\n>>> p\narray([[0, 1, 2, 3, 4, 5, 6],\n       [0, 0, 0, 9, 0, 0, 0]])\n\nWe take elements of the ``p`` array as coordinates of seven points on the\nplane, where ``p[:, j]`` gives the coordinates of the point\n:math:`\\mathbf{p}_j`.\n\nFirst, consider the *uniform* parametrization, :math:`u_j = j`:\n\n>>> u_unif = x\n\nSecond, we consider the so-called *cord length* parametrization, which is\nnothing but a cumulative length of straight line segments connecting the\ndata points:\n\n.. math::\n\n    u_j = u_{j-1} + |\\mathbf{p}_j - \\mathbf{p}_{j-1}|\n\nfor :math:`j=1, 2, \\dots` and :math:`u_0 = 0`. Here :math:`| \\cdots |` is the\nlength between the consecutive points :math:`p_j` on the plane.\n\n>>> dp = p[:, 1:] - p[:, :-1]      # 2-vector distances between points\n>>> l = (dp**2).sum(axis=0)        # squares of lengths of 2-vectors between points\n>>> u_cord = np.sqrt(l).cumsum()   # cumulative sums of 2-norms\n>>> u_cord = np.r_[0, u_cord]      # the first point is parameterized at zero\n\nFinally, we consider what is sometimes called the *centripetal*\nparametrization: :math:`u_j = u_{j-1} + |\\mathbf{p}_j - \\mathbf{p}_{j-1}|^{1/2}`.\nDue to the extra square root, the difference between consecutive values\n:math:`u_j - u_{j-1}` will be smaller than for the cord length parametrization: \n\n>>> u_c = np.r_[0, np.cumsum((dp**2).sum(axis=0)**0.25)]\n\nNow plot the resulting curves:\n\n>>> from scipy.interpolate import make_interp_spline\n>>> import matplotlib.pyplot as plt\n>>> fig, ax = plt.subplots(1, 3, figsize=(8, 3))\n>>> parametrizations = ['uniform', 'cord length', 'centripetal']\n>>>\n>>> for j, u in enumerate([u_unif, u_cord, u_c]):\n...    spl = make_interp_spline(u, p, axis=1)    # note p is a 2D array\n...    \n...    uu = np.linspace(u[0], u[-1], 51)\n...    xx, yy = spl(uu)\n...    \n...    ax[j].plot(xx, yy, '--')\n...    ax[j].plot(p[0, :], p[1, :], 'o')\n...    ax[j].set_title(parametrizations[j])\n>>> plt.show()",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Parametric spline curves"
        }
      ],
      "level": 1,
      "target": "tutorial-interpolate_parametric"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "We note that "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "scipy.interpolate",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "*",
                "kind": "api",
                "path": "scipy.interpolate"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " does "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "not"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " support interpolation with missing data. Two popular ways of representing missing data are using masked arrays of the "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.ma",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy.ma"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " library, and encoding missing values as not-a-number, "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "NaN"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Neither of these two approaches is directly supported in "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "scipy.interpolate",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "*",
                "kind": "api",
                "path": "scipy.interpolate"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Individual routines may offer partial support, and/or workarounds, but in general, the library firmly adheres to the IEEE 754 semantics where a "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "NaN"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " means "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "not-a-number"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", i.e. a result of an illegal mathematical operation (e.g., division by zero), not "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "missing"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Missing data"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "note",
          "base_type": "note",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "note "
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "InlineRole",
                  "__tag": 4003,
                  "value": "interp1d",
                  "domain": null,
                  "role": null,
                  "inventory": null
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " is considered legacy API and is not recommended for use in new code. Consider using "
                },
                {
                  "__type": "CrossRef",
                  "__tag": 4002,
                  "value": "more specific interpolators instead",
                  "reference": {
                    "__type": "LocalRef",
                    "__tag": 4022,
                    "kind": "docs",
                    "path": "tutorial:interpolate:1D"
                  },
                  "kind": "exists"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "."
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "interp1d",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " class in "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "scipy.interpolate",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "*",
                "kind": "api",
                "path": "scipy.interpolate"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is a convenient method to create a function based on fixed data points, which can be evaluated anywhere within the domain defined by the given data using linear interpolation. An instance of this class is created by passing the 1-D vectors comprising the data. The instance of this class defines a "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "__call__"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " method and can therefore be treated like a function which interpolates between known data values to obtain unknown values. Behavior at the boundary can be specified at instantiation time. The following example demonstrates its use, for linear and cubic spline interpolation:"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> from scipy.interpolate import interp1d\n\n>>> x = np.linspace(0, 10, num=11, endpoint=True)\n>>> y = np.cos(-x**2/9.0)\n>>> f = interp1d(x, y)\n>>> f2 = interp1d(x, y, kind='cubic')\n\n>>> xnew = np.linspace(0, 10, num=41, endpoint=True)\n>>> import matplotlib.pyplot as plt\n>>> plt.plot(x, y, 'o', xnew, f(xnew), '-', xnew, f2(xnew), '--')\n>>> plt.legend(['data', 'linear', 'cubic'], loc='best')\n>>> plt.show()",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The 'cubic' kind of "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "interp1d",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is equivalent to "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "make_interp_spline",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and the 'linear' kind is equivalent to "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.interp",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:interp"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " while also allowing N-dimensional "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "y"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " arrays."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Another set of interpolations in "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "interp1d",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "nearest",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "previous",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "next",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", where they return the nearest, previous, or next point along the x-axis. Nearest and next can be thought of as a special case of a causal interpolating filter. The following example demonstrates their use, using the same data as in the previous example:"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> from scipy.interpolate import interp1d\n\n>>> x = np.linspace(0, 10, num=11, endpoint=True)\n>>> y = np.cos(-x**2/9.0)\n>>> f1 = interp1d(x, y, kind='nearest')\n>>> f2 = interp1d(x, y, kind='previous')\n>>> f3 = interp1d(x, y, kind='next')\n\n>>> xnew = np.linspace(0, 10, num=1001, endpoint=True)\n>>> import matplotlib.pyplot as plt\n>>> plt.plot(x, y, 'o')\n>>> plt.plot(xnew, f1(xnew), '-', xnew, f2(xnew), '--', xnew, f3(xnew), ':')\n>>> plt.legend(['data', 'nearest', 'previous', 'next'], loc='best')\n>>> plt.show()",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Legacy interface for 1-D interpolation ("
        },
        {
          "__type": "InlineRole",
          "__tag": 4003,
          "value": "interp1d",
          "domain": null,
          "role": "class",
          "inventory": null
        },
        {
          "__type": "Text",
          "__tag": 4046,
          "value": ")"
        }
      ],
      "level": 1,
      "target": "tutorial-interpolate_interp1d"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "As mentioned, "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "interp1d",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " class is "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "legacy"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ": we have no plans to remove it; we are going to keep supporting its existing usages; however we believe there are better alternatives which we recommend using in new code."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Here we list specific recommendations, depending on the interpolation "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "kind"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Linear interpolation,"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "kind=\"linear\""
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The default recommendation is to use "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.interp",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:interp"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " function. Alternatively, you can use linear splines, "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "make_interp_spline(x, y, k=1)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", see "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "this section for a discussion<tutorial-interpolate_linear_spline>",
              "domain": null,
              "role": "ref",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Spline interpolators,"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "kind=\"quadratic\""
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " or "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "\"cubic\""
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Under the hood, "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "interp1d",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " delegates to "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "make_interp_spline",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", so we recommend using the latter directly."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Piecewise constant modes,"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "kind=\"nearest\", \"previous\", \"next\""
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "First, we note that "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "interp1d(x, y, kind='previous')"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is equivalent to "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "make_interp_spline(x, y, k=0)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "More generally however, all these piecewise constant interpolation modes are based on "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.searchsorted",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:searchsorted"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". For example, the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "\"nearest\""
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " mode is nothing but"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> x = np.arange(8)\n>>> y = x**2\n>>> x_new = np.linspace(0, 7, 101)    # input points\n>>> x_bds = x[:-1] / 2.0 + x[1:] / 2.0   # halfway points\n>>> idx = np.searchsorted(x_bds, x_new, side='left')\n>>> idx = np.clip(idx, 0, len(x) - 1)  # clip the indices so that they are within the range of x indices.\n>>> import matplotlib.pyplot as plt\n>>> plt.plot(x, y, 'o')\n>>> plt.plot(x_new, y[idx], '--')\n>>> plt.show()",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Other variants are similar, see the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "interp1d"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " "
            },
            {
              "__type": "Link",
              "__tag": 4049,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "source code"
                }
              ],
              "url": "https://github.com/scipy/scipy/blob/v1.14.1/scipy/interpolate/_interpolate.py#L486",
              "title": ""
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for details."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Recommended replacements for "
        },
        {
          "__type": "InlineRole",
          "__tag": 4003,
          "value": "interp1d",
          "domain": null,
          "role": null,
          "inventory": null
        },
        {
          "__type": "Text",
          "__tag": 4046,
          "value": " modes"
        }
      ],
      "level": 2,
      "target": "tutorial-interpolate_interp1d_replacements"
    }
  ],
  "local_refs": []
}