{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Raises": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Yields": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Methods": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Construct a piecewise polynomial from a spline"
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Receives": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warnings": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Attributes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "tck",
              "annotation": "",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "A spline, as returned by "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "splrep",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " or a BSpline object."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "extrapolate",
              "annotation": "bool or 'periodic', optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If bool, determines whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. If 'periodic', periodic extrapolation is used. Default is True."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Other Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    }
  },
  "_ordered_sections": [
    "Summary",
    "Extended Summary",
    "Parameters",
    "Attributes",
    "Methods",
    "Returns",
    "Yields",
    "Receives",
    "Other Parameters",
    "Raises",
    "Warns",
    "Warnings",
    "Notes"
  ],
  "item_file": "/scipy/interpolate/_interpolate.py",
  "item_line": 1196,
  "item_type": "classmethod",
  "aliases": [
    "scipy.interpolate.PPoly.from_spline"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "Construct an interpolating spline and convert it to a `PPoly` instance\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nfrom scipy.interpolate import splrep, PPoly\nx = np.linspace(0, 1, 11)\ny = np.sin(2*np.pi*x)\ntck = splrep(x, y, s=0)\np = PPoly.from_spline(tck)\nisinstance(p, PPoly)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nNote that this function only supports 1D splines out of the box.\n\nIf the ``tck`` object represents a parametric spline (e.g. constructed\nby `splprep` or a `BSpline` with ``c.ndim > 1``), you will need to loop\nover the dimensions manually.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "from scipy.interpolate import splprep, splev\nt = np.linspace(0, 1, 11)\nx = np.sin(2*np.pi*t)\ny = np.cos(2*np.pi*t)\n(t, c, k), u = splprep([x, y], s=0)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nNote that ``c`` is a list of two arrays of length 11.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "unew = np.arange(0, 1.01, 0.01)\nout = splev(unew, (t, c, k))\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nTo convert this spline to the power basis, we convert each\ncomponent of the list of b-spline coefficients, ``c``, into the\ncorresponding cubic polynomial.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "polys = [PPoly.from_spline((t, cj, k)) for cj in c]\npolys[0].c.shape\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nNote that the coefficients of the polynomials `polys` are in the\npower basis and their dimensions reflect just that: here 4 is the order\n(degree+1), and 14 is the number of intervals---which is nothing but\nthe length of the knot array of the original `tck` minus one.\n\nOptionally, we can stack the components into a single `PPoly` along\nthe third dimension:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "cc = np.dstack([p.c for p in polys])    # has shape = (4, 14, 2)\npoly = PPoly(cc, polys[0].x)\nnp.allclose(poly(unew).T,     # note the transpose to match `splev`\n            out, atol=1e-15)\n",
        "execution_status": "success"
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": null,
  "references": null,
  "qa": "scipy.interpolate._interpolate:PPoly.from_spline",
  "arbitrary": [],
  "local_refs": [
    "extrapolate",
    "tck"
  ]
}