{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Image "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " illustrates trapezoidal rule -- y-axis locations of points will be taken from "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "y"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " array, by default x-axis distances between points will be 1.0, alternatively they can be provided with "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " array or with "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "dx"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " scalar.  Return value will be equal to combined area under the red lines."
            }
          ]
        },
        {
          "__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": "trapezoid",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": null,
                "version": null,
                "kind": "local",
                "path": "trapezoid"
              },
              "kind": "local"
            },
            {
              "__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                   ⛔                     ⛔                   \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": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "trapezoid",
              "annotation": "float or ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Definite integral of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "y"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " = n-dimensional array as approximated along a single axis by the trapezoidal rule. If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "y"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is a 1-dimensional array, then the result is a float. If "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "n",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is greater than 1, then the result is an "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "n",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "-1 dimensional array."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Integrate along the given axis using the composite trapezoidal rule."
            }
          ]
        }
      ],
      "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": "y",
              "annotation": "array_like",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Input array to integrate."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "x",
              "annotation": "array_like, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The sample points corresponding to the "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "y"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " values. If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is None, the sample points are assumed to be evenly spaced "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "dx"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " apart. The default is None."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "dx",
              "annotation": "scalar, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The spacing between sample points when "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is None. The default is 1."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "axis",
              "annotation": "int, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The axis along which to integrate. The default is the last axis."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is provided, the integration happens in sequence along its elements - they are not sorted."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Integrate "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "y"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " ("
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ") along each 1d slice on the given axis, compute "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\int y(x) dx"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". When "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is specified, this integrates along the parametric curve, computing "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\int_t y(t) dt = \\int_t y(t) \\left.\\frac{dx}{dt}\\right|_{x=x(t)} dt"
            },
            {
              "__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/integrate/_quadrature.py",
  "item_line": 21,
  "item_type": "function",
  "aliases": [
    "scipy.integrate.trapezoid"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "Use the trapezoidal rule on evenly spaced points:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nfrom scipy import integrate\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "integrate.trapezoid([1, 2, 3])\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThe spacing between sample points can be selected by either the\n``x`` or ``dx`` arguments:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "integrate.trapezoid([1, 2, 3], x=[4, 6, 8])\nintegrate.trapezoid([1, 2, 3], dx=2)\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nUsing a decreasing ``x`` corresponds to integrating in reverse:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "integrate.trapezoid([1, 2, 3], x=[8, 6, 4])\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nMore generally ``x`` is used to integrate along a parametric curve. We can\nestimate the integral :math:`\\int_0^1 x^2 = 1/3` using:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "x = np.linspace(0, 1, num=50)\ny = x**2\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "integrate.trapezoid(y, x)\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nOr estimate the area of a circle, noting we repeat the sample which closes\nthe curve:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "theta = np.linspace(0, 2 * np.pi, num=1000, endpoint=True)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "integrate.trapezoid(np.cos(theta), x=np.sin(theta))\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\n``trapezoid`` can be applied along a specified axis to do multiple\ncomputations in one call:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "a = np.arange(6).reshape(2, 3)\na\nintegrate.trapezoid(a, axis=0)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "integrate.trapezoid(a, axis=1)\n",
        "execution_status": "failure"
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "cumulative_trapezoid",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy.integrate._quadrature:cumulative_trapezoid"
        },
        "kind": "module"
      },
      "descriptions": [],
      "type": "func"
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "romb",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy.integrate._quadrature:romb"
        },
        "kind": "module"
      },
      "descriptions": [],
      "type": "func"
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "simpson",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy.integrate._quadrature:simpson"
        },
        "kind": "module"
      },
      "descriptions": [],
      "type": "func"
    }
  ],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "y",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "x",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "dx",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "1.0"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "axis",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "-1"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "trapezoid"
  },
  "references": [
    ".. [1] Wikipedia page: https://en.wikipedia.org/wiki/Trapezoidal_rule",
    "",
    ".. [2] Illustration image:",
    "       https://en.wikipedia.org/wiki/File:Composite_trapezoidal_rule_illustration.png"
  ],
  "qa": "scipy.integrate._quadrature:trapezoid",
  "arbitrary": [],
  "local_refs": [
    "axis",
    "dx",
    "trapezoid",
    "x",
    "y"
  ]
}