{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "B-spline basis elements are defined via"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "B_{i, 0}(x) = 1, \\textrm{if $t_i \\le x < t_{i+1}$, otherwise $0$,}\n\nB_{i, k}(x) = \\frac{x - t_i}{t_{i+k} - t_i} B_{i, k-1}(x)\n         + \\frac{t_{i+k+1} - x}{t_{i+k+1} - t_{i+1}} B_{i+1, k-1}(x)"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Implementation details"
                }
              ]
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "At least "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "k+1"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " coefficients are required for a spline of degree "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "k"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ",   so that "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "n >= k+1"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Additional coefficients, "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "c[j]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " with   "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "j > n"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", are ignored."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "B-spline basis elements of degree "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "k"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " form a partition of unity on the   "
                    },
                    {
                      "__type": "Emphasis",
                      "__tag": 4047,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "base interval"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "t[k] <= x <= t[n]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Array API Standard Support"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "BSpline",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.interpolate._bsplines:BSpline"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "SCIPY_ARRAY_API=1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported."
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "====================  ====================  ====================\nLibrary               CPU                   GPU\n====================  ====================  ====================\nNumPy                 ✅                     n/a                 \nCuPy                  n/a                   ⛔                   \nPyTorch               ✅                     ⛔                   \nJAX                   ⚠️ no JIT             ⛔                   \nDask                  ⛔                     n/a                 \n====================  ====================  ====================",
          "execution_status": null
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "See "
                },
                {
                  "__type": "InlineRole",
                  "__tag": 4003,
                  "value": "dev-arrayapi",
                  "domain": null,
                  "role": "ref",
                  "inventory": null
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " for more information."
                }
              ]
            }
          ]
        }
      ],
      "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": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "__call__",
              "annotation": "",
              "desc": []
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "basis_element",
              "annotation": "",
              "desc": []
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "derivative",
              "annotation": "",
              "desc": []
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "antiderivative",
              "annotation": "",
              "desc": []
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "integrate",
              "annotation": "",
              "desc": []
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "insert_knot",
              "annotation": "",
              "desc": []
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "construct_fast",
              "annotation": "",
              "desc": []
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "design_matrix",
              "annotation": "",
              "desc": []
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "from_power_basis",
              "annotation": "",
              "desc": []
            }
          ]
        }
      ],
      "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": "Univariate spline in the B-spline basis."
            }
          ]
        }
      ],
      "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": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "t",
              "annotation": "ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "knot vector"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "c",
              "annotation": "ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "spline coefficients"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "k",
              "annotation": "int",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "spline degree"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "extrapolate",
              "annotation": "bool",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If True, extrapolates the first and last polynomial pieces of b-spline functions active on the base interval."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "axis",
              "annotation": "int",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Interpolation axis."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "tck",
              "annotation": "tuple",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "A read-only equivalent of "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(self.t, self.c, self.k)"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "t",
              "annotation": "ndarray, shape (n+k+1,)",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "knots"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "c",
              "annotation": "ndarray, shape (>=n, ...)",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "spline coefficients"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "k",
              "annotation": "int",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "B-spline degree"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "extrapolate",
              "annotation": "bool or 'periodic', optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "whether to extrapolate beyond the base interval, "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "t[k] .. t[n]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", or to return nans. If True, extrapolates the first and last polynomial pieces of b-spline functions active on the base interval. If 'periodic', periodic extrapolation is used. Default is True."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "axis",
              "annotation": "int, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Interpolation axis. Default is zero."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "S(x) = \\sum_{j=0}^{n-1} c_j  B_{j, k; t}(x)"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "where "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "B_{j, k; t}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " are B-spline basis functions of degree "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "k"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and knots "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "t"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "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/_bsplines.py",
  "item_line": 70,
  "item_type": "class",
  "aliases": [
    "scipy.interpolate.BSpline"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "Translating the recursive definition of B-splines into Python code, we have:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "def B(x, k, i, t):\n   if k == 0:\n      return 1.0 if t[i] <= x < t[i+1] else 0.0\n   if t[i+k] == t[i]:\n      c1 = 0.0\n   else:\n      c1 = (x - t[i])/(t[i+k] - t[i]) * B(x, k-1, i, t)\n   if t[i+k+1] == t[i+1]:\n      c2 = 0.0\n   else:\n      c2 = (t[i+k+1] - x)/(t[i+k+1] - t[i+1]) * B(x, k-1, i+1, t)\n   return c1 + c2\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "def bspline(x, t, c, k):\n   n = len(t) - k - 1\n   assert (n >= k+1) and (len(c) >= n)\n   return sum(c[i] * B(x, k, i, t) for i in range(n))\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nNote that this is an inefficient (if straightforward) way to\nevaluate B-splines --- this spline class does it in an equivalent,\nbut much more efficient way.\n\nHere we construct a quadratic spline function on the base interval\n``2 <= x <= 4`` and compare with the naive way of evaluating the spline:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "from scipy.interpolate import BSpline\nk = 2\nt = [0, 1, 2, 3, 4, 5, 6]\nc = [-1, 2, 0, -1]\nspl = BSpline(t, c, k)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "spl(2.5)\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "bspline(2.5, t, c, k)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nNote that outside of the base interval results differ. This is because\n`BSpline` extrapolates the first and last polynomial pieces of B-spline\nfunctions active on the base interval.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import matplotlib.pyplot as plt\nimport numpy as np\nfig, ax = plt.subplots()\nxx = np.linspace(1.5, 4.5, 50)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax.plot(xx, [bspline(x, t, c ,k) for x in xx], 'r-', lw=3, label='naive')\nax.plot(xx, spl(xx), 'b-', lw=4, alpha=0.7, label='BSpline')\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax.grid(True)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax.legend(loc='best')\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.show()\n",
        "execution_status": "success"
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "1.17.1",
          "kind": "assets",
          "path": "fig-a22e510536011789.png"
        }
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "t",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "c",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "k",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "extrapolate",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "True"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "axis",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "0"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "BSpline"
  },
  "references": [
    ".. [1] Tom Lyche and Knut Morken, Spline methods,",
    "    http://www.uio.no/studier/emner/matnat/ifi/INF-MAT5340/v05/undervisningsmateriale/",
    ".. [2] Carl de Boor, A practical guide to splines, Springer, 2001."
  ],
  "qa": "scipy.interpolate._bsplines:BSpline",
  "arbitrary": [],
  "local_refs": [
    "__call__",
    "antiderivative",
    "axis",
    "basis_element",
    "c",
    "construct_fast",
    "derivative",
    "design_matrix",
    "extrapolate",
    "from_power_basis",
    "insert_knot",
    "integrate",
    "k",
    "t",
    "tck"
  ]
}