{
  "__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": "out",
              "annotation": "ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The drawn samples, of shape size, if provided. When size is provided, the output shape is size + (p,)  If not specified, the shape is determined by the broadcast shape of "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "n"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "pvals"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(b0, b1, ..., bq)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " augmented with the dimension of the multinomial, "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "p"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", so that that output shape is "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(b0, b1, ..., bq, p)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Each entry "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "out[i,j,...,:]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is a "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "p"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "-dimensional value drawn from the distribution."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "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 multinomial 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": "n",
              "annotation": "int or array-like of ints",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Number of experiments."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "pvals",
              "annotation": "array-like of floats",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Probabilities of each of the "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "p"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " different outcomes with shape "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(k0, k1, ..., kn, p)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Each element "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "pvals[i,j,...,:]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " must sum to 1 (however, the last element is always assumed to account for the remaining probability, as long as "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "sum(pvals[..., :-1], axis=-1) <= 1.0"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Must have at least 1 dimension where pvals.shape[-1] > 0."
                    }
                  ]
                }
              ]
            },
            {
              "__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 each with "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "p"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " elements. Default is None where the output size is determined by the broadcast shape of "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "n"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and all by the final dimension of "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "pvals"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", which is denoted as "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "b=(b0, b1, ..., bq)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". If size is not None, then it must be compatible with the broadcast shape "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "b"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Specifically, size must have "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "q"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " or more elements and size[-(q-j):] must equal "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "bj"
                    },
                    {
                      "__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": "The multinomial distribution is a multivariate generalization of the binomial distribution.  Take an experiment with one of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "p"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " possible outcomes.  An example of such an experiment is throwing a dice, where the outcome can be 1 through 6.  Each sample drawn from the distribution represents "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "n"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " such experiments.  Its values, "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "X_i = [X_0, X_1, ..., X_p]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", represent the number of times the outcome was "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "i"
            },
            {
              "__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.multinomial"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "Throw a dice 20 times:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "rng = np.random.default_rng()\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "rng.multinomial(20, [1/6.]*6, size=1)\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nIt landed 4 times on 1, once on 2, etc.\n\nNow, throw the dice 20 times, and 20 times again:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "rng.multinomial(20, [1/6.]*6, size=2)\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nFor the first run, we threw 3 times 1, 4 times 2, etc.  For the second,\nwe threw 2 times 1, 4 times 2, etc.\n\nNow, do one experiment throwing the dice 10 time, and 10 times again,\nand another throwing the dice 20 times, and 20 times again:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "rng.multinomial([[10], [20]], [1/6.]*6, size=(2, 2))\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThe first array shows the outcomes of throwing the dice 10 times, and\nthe second shows the outcomes from throwing the dice 20 times.\n\nA loaded die is more likely to land on number 6:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "rng.multinomial(100, [1/7.]*5 + [2/7.])\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nSimulate 10 throws of a 4-sided die and 20 throws of a 6-sided die\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "rng.multinomial([10, 20],[[1/4]*4 + [0]*2, [1/6]*6])\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nGenerate categorical random variates from two categories where the\nfirst has 3 outcomes and the second has 2.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "rng.multinomial(1, [[.1, .5, .4 ], [.3, .7, .0]])\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\n``argmax(axis=-1)`` is then used to return the categories.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "pvals = [[.1, .5, .4 ], [.3, .7, .0]]\nrvs = rng.multinomial(1, pvals, size=(4,2))\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "rvs.argmax(axis=-1)\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThe same output dimension can be produced using broadcasting.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "rvs = rng.multinomial([[1]] * 4, pvals)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "rvs.argmax(axis=-1)\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThe probability inputs should be normalized. As an implementation\ndetail, the value of the last entry is ignored and assumed to take\nup any leftover probability mass, but this should not be relied on.\nA biased coin which has twice as much weight on one side as on the\nother should be sampled like so:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "rng.multinomial(100, [1.0 / 3, 2.0 / 3])  # RIGHT\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nnot like:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "rng.multinomial(100, [1.0, 2.0])  # WRONG\n",
        "execution_status": "success"
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "n",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "pvals",
        "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": "multinomial"
  },
  "references": null,
  "qa": "numpy.random._generator:Generator.multinomial",
  "arbitrary": [],
  "local_refs": [
    "n",
    "out",
    "pvals",
    "size"
  ]
}