{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The probability mass function (PMF) for the Hypergeometric distribution is"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "P(x) = \\frac{\\binom{g}{x}\\binom{b}{n-x}}{\\binom{g+b}{n}},"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "where "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "0 \\le x \\le n"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "n-b \\le x \\le g"
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "for P(x) the probability of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " good results in the drawn sample, g = "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "ngood"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", b = "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "nbad"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and n = "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "nsample"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Consider an urn with black and white marbles in it, "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "ngood"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " of them are black and "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "nbad"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " are white. If you draw "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "nsample"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " balls without replacement, then the hypergeometric distribution describes the distribution of black balls in the drawn sample."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Note that this distribution is very similar to the binomial distribution, except that in this case, samples are drawn without replacement, whereas in the Binomial case samples are drawn with replacement (or the sample space is infinite). As the sample space becomes large, this distribution approaches the binomial."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The arguments "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "ngood"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "nbad"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " each must be less than "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "10**9",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". For extremely large arguments, the algorithm that is used to compute the samples "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "4"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " breaks down because of loss of precision in floating point calculations.  For such large values, if "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "nsample"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is not also large, the distribution can be approximated with the binomial distribution, "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "binomial(n=nsample, p=ngood/(ngood + nbad))",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "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": "out",
              "annotation": "ndarray or scalar",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Drawn samples from the parameterized hypergeometric distribution. Each sample is the number of good items within a randomly selected subset of size "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "nsample"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " taken from a set of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "ngood"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " good items and "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "nbad"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " bad items."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Draw samples from a Hypergeometric distribution."
            }
          ]
        }
      ],
      "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": "ngood",
              "annotation": "int or array_like of ints",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Number of ways to make a good selection.  Must be nonnegative and less than 10**9."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "nbad",
              "annotation": "int or array_like of ints",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Number of ways to make a bad selection.  Must be nonnegative and less than 10**9."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "nsample",
              "annotation": "int or array_like of ints",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Number of items sampled.  Must be nonnegative and less than "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "ngood + nbad"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "size",
              "annotation": "int or tuple of ints, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Output shape.  If the given shape is, e.g., "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(m, n, k)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", then "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "m * n * k"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " samples are drawn.  If size is "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "None"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " (default), a single value is returned if "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "ngood"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "nbad"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", and "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "nsample"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " are all scalars.  Otherwise, "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "np.broadcast(ngood, nbad, nsample).size"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " samples are drawn."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Samples are drawn from a hypergeometric distribution with specified parameters, "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "ngood"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " (ways to make a good selection), "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "nbad"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " (ways to make a bad selection), and "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "nsample"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " (number of items sampled, which is less than or equal to the sum "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "ngood + nbad"
            },
            {
              "__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": null,
  "item_line": null,
  "item_type": "cython_function_or_method",
  "aliases": [
    "numpy.random.Generator.hypergeometric"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "Draw samples from the distribution:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "rng = np.random.default_rng()\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ngood, nbad, nsamp = 100, 2, 10\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "s = rng.hypergeometric(ngood, nbad, nsamp, 1000)\nfrom matplotlib.pyplot import hist\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "hist(s)\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nSuppose you have an urn with 15 white and 15 black marbles.\nIf you pull 15 marbles at random, how likely is it that\n12 or more of them are one color?\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "s = rng.hypergeometric(15, 15, 15, 100000)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "sum(s>=12)/100000. + sum(s<=3)/100000.\n",
        "execution_status": "failure"
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "multivariate_hypergeometric",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "numpy.random._generator:Generator.multivariate_hypergeometric"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Draw samples from the multivariate hypergeometric distribution."
            }
          ]
        }
      ],
      "type": null
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "scipy.stats.hypergeom",
        "reference": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "current-module",
          "version": "current-version",
          "kind": "to-resolve",
          "path": "scipy.stats.hypergeom"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "probability density function, distribution or cumulative density function, etc."
            }
          ]
        }
      ],
      "type": null
    }
  ],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "ngood",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "nbad",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "nsample",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "size",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "hypergeometric"
  },
  "references": [
    ".. [1] Lentner, Marvin, \"Elementary Applied Statistics\", Bogden",
    "       and Quigley, 1972.",
    ".. [2] Weisstein, Eric W. \"Hypergeometric Distribution.\" From",
    "       MathWorld--A Wolfram Web Resource.",
    "       https://mathworld.wolfram.com/HypergeometricDistribution.html",
    ".. [3] Wikipedia, \"Hypergeometric distribution\",",
    "       https://en.wikipedia.org/wiki/Hypergeometric_distribution",
    ".. [4] Stadlober, Ernst, \"The ratio of uniforms approach for generating",
    "       discrete random variates\", Journal of Computational and Applied",
    "       Mathematics, 31, pp. 181-189 (1990)."
  ],
  "qa": "numpy.random._generator:Generator.hypergeometric",
  "arbitrary": [],
  "local_refs": [
    "nbad",
    "ngood",
    "nsample",
    "out",
    "size"
  ]
}