{
  "__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": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "X",
              "annotation": "`ContinuousDistribution`",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The truncated random variable."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Truncate the support of a random variable."
            }
          ]
        }
      ],
      "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": "X",
              "annotation": "`ContinuousDistribution`",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The random variable to be truncated."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "lb, ub",
              "annotation": "float array-like",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The lower and upper truncation points, respectively. Must be broadcastable with one another and the shape of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "X"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Given a random variable "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "X"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "truncate",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.stats._distribution_infrastructure:truncate"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " returns a random variable with support truncated to the interval between "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "lb"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "ub"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The underlying probability density function is normalized accordingly."
            }
          ]
        }
      ],
      "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": "build-install/usr/lib/python3.14/site-packages/scipy/stats/_distribution_infrastructure.py",
  "item_line": 4588,
  "item_type": "function",
  "aliases": [
    "scipy.stats.truncate"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "Compare against `scipy.stats.truncnorm`, which truncates a standard normal,\n*then* shifts and scales it.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy import stats\nloc, scale, lb, ub = 1, 2, -2, 2\nX = stats.truncnorm(lb, ub, loc, scale)\nY = scale * stats.truncate(stats.Normal(), lb, ub) + loc\nx = np.linspace(-3, 5, 300)\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.plot(x, X.pdf(x), '-', label='X')\nplt.plot(x, Y.pdf(x), '--', label='Y')\nplt.xlabel('x')\nplt.ylabel('PDF')\nplt.title('Truncated, then Shifted/Scaled Normal')\nplt.legend()\n",
        "execution_status": "failure",
        "out": "<matplotlib.legend.Legend object at 0x7f3f68548440>\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.show()\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "2.0.0.dev0+git20260907.41eeb59",
          "kind": "assets",
          "path": "fig-193af4d3851ac4e2.png"
        }
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nHowever, suppose we wish to shift and scale a normal random variable,\nthen truncate its support to given values. This is straightforward with\n`truncate`.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "Z = stats.truncate(scale * stats.Normal() + loc, lb, ub)\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "Z.plot()\n",
        "execution_status": "failure",
        "out": "<Axes: title={'center': 'truncate(2.0*StandardNormal() + 1.0, lb=-2.0, ub=2.0)'}, xlabel='$x$', ylabel='$pdf$'>\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.show()\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "2.0.0.dev0+git20260907.41eeb59",
          "kind": "assets",
          "path": "fig-5a97c9adabfac47f.png"
        }
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nFurthermore, `truncate` can be applied to any random variable:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "Rayleigh = stats.make_distribution(stats.rayleigh)\nW = stats.truncate(Rayleigh(), lb=0.5, ub=3)\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "W.plot()\n",
        "execution_status": "failure",
        "out": "<Axes: title={'center': 'truncate(Rayleigh(), lb=0.5, ub=3.0)'}, xlabel='$x$', ylabel='$pdf$'>\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.show()\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "2.0.0.dev0+git20260907.41eeb59",
          "kind": "assets",
          "path": "fig-a9d6d778c4b2c85a.png"
        }
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "X",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "lb",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "-inf"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "ub",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "inf"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "truncate"
  },
  "references": [
    ".. [1] \"Truncated Distribution\". *Wikipedia*.",
    "       https://en.wikipedia.org/wiki/Truncated_distribution"
  ],
  "qa": "scipy.stats._distribution_infrastructure:truncate",
  "arbitrary": [],
  "local_refs": [
    "X",
    "lb",
    "ub"
  ]
}