{
  "__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": "res",
              "annotation": "sparse array",
              "desc": []
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Return a sparse array of uniformly random numbers in [0, 1)"
            }
          ]
        }
      ],
      "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": "shape",
              "annotation": "tuple of int",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "shape of the array."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "density",
              "annotation": "real, optional (default: 0.01)",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "density of the generated matrix: density equal to one means a full matrix, density of 0 means a matrix with no non-zero items."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "format",
              "annotation": "str, optional (default: 'coo')",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "sparse matrix format."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "dtype",
              "annotation": "dtype, optional (default: np.float64)",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "type of the returned matrix values."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "rng",
              "annotation": "{None, int, `numpy.random.Generator`}, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "rng"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is passed by keyword, types other than "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "numpy.random.Generator",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "numpy",
                        "version": "*",
                        "kind": "api",
                        "path": "numpy.random._generator:Generator"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " are passed to "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "numpy.random.default_rng",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "numpy",
                        "version": "*",
                        "kind": "api",
                        "path": "numpy.random:default_rng"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " to instantiate a "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "Generator"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "rng"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is already a "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "Generator"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " instance, then the provided instance is used. Specify "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "rng"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " for repeatable function behavior."
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If this argument is passed by position or "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "random_state"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is passed by keyword, legacy behavior for the argument "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "random_state"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " applies:"
                    }
                  ]
                },
                {
                  "__type": "BulletList",
                  "__tag": 4053,
                  "ordered": false,
                  "start": 1,
                  "children": [
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "If "
                            },
                            {
                              "__type": "ParamRef",
                              "__tag": 4071,
                              "name": "random_state"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": " is None (or "
                            },
                            {
                              "__type": "CrossRef",
                              "__tag": 4002,
                              "value": "numpy.random",
                              "reference": {
                                "__type": "RefInfo",
                                "__tag": 4000,
                                "module": "numpy",
                                "version": "*",
                                "kind": "api",
                                "path": "numpy.random"
                              },
                              "kind": "module"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "), the "
                            },
                            {
                              "__type": "CrossRef",
                              "__tag": 4002,
                              "value": "numpy.random.RandomState",
                              "reference": {
                                "__type": "RefInfo",
                                "__tag": 4000,
                                "module": "numpy",
                                "version": "*",
                                "kind": "api",
                                "path": "numpy.random.mtrand:RandomState"
                              },
                              "kind": "module"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "   singleton is used."
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "If "
                            },
                            {
                              "__type": "ParamRef",
                              "__tag": 4071,
                              "name": "random_state"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": " is an int, a new "
                            },
                            {
                              "__type": "InlineCode",
                              "__tag": 4051,
                              "value": "RandomState"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": " instance is used,   seeded with "
                            },
                            {
                              "__type": "ParamRef",
                              "__tag": 4071,
                              "name": "random_state"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "."
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "If "
                            },
                            {
                              "__type": "ParamRef",
                              "__tag": 4071,
                              "name": "random_state"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": " is already a "
                            },
                            {
                              "__type": "InlineCode",
                              "__tag": 4051,
                              "value": "Generator"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": " or "
                            },
                            {
                              "__type": "InlineCode",
                              "__tag": 4051,
                              "value": "RandomState"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": " instance then   that instance is used."
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "__type": "Admonition",
                  "__tag": 4056,
                  "kind": "versionchanged",
                  "base_type": "neutral",
                  "children": [
                    {
                      "__type": "AdmonitionTitle",
                      "__tag": 4055,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "versionchanged 1.15.0"
                        }
                      ]
                    },
                    {
                      "__type": "Paragraph",
                      "__tag": 4045,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "As part of the "
                        },
                        {
                          "__type": "Link",
                          "__tag": 4049,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "SPEC-007"
                            }
                          ],
                          "url": "https://scientific-python.org/specs/spec-0007/",
                          "title": ""
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " transition from use of "
                        },
                        {
                          "__type": "CrossRef",
                          "__tag": 4002,
                          "value": "numpy.random.RandomState",
                          "reference": {
                            "__type": "RefInfo",
                            "__tag": 4000,
                            "module": "numpy",
                            "version": "*",
                            "kind": "api",
                            "path": "numpy.random.mtrand:RandomState"
                          },
                          "kind": "module"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " to "
                        },
                        {
                          "__type": "CrossRef",
                          "__tag": 4002,
                          "value": "numpy.random.Generator",
                          "reference": {
                            "__type": "RefInfo",
                            "__tag": 4000,
                            "module": "numpy",
                            "version": "*",
                            "kind": "api",
                            "path": "numpy.random._generator:Generator"
                          },
                          "kind": "module"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": ", this keyword was changed from "
                        },
                        {
                          "__type": "ParamRef",
                          "__tag": 4071,
                          "name": "random_state"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " to "
                        },
                        {
                          "__type": "ParamRef",
                          "__tag": 4071,
                          "name": "rng"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": ". For an interim period, both keywords will continue to work, although only one may be specified at a time. After the interim period, function calls using the "
                        },
                        {
                          "__type": "ParamRef",
                          "__tag": 4071,
                          "name": "random_state"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " keyword will emit warnings. The behavior of both "
                        },
                        {
                          "__type": "ParamRef",
                          "__tag": 4071,
                          "name": "random_state"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " and "
                        },
                        {
                          "__type": "ParamRef",
                          "__tag": 4071,
                          "name": "rng"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " are outlined above, but only the "
                        },
                        {
                          "__type": "ParamRef",
                          "__tag": 4071,
                          "name": "rng"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " keyword should be used in new code."
                        }
                      ]
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "This random state will be used for sampling "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "indices"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " (the sparsity structure), and by default for the data values too (see "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "data_sampler"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ")."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "data_sampler",
              "annotation": "callable, optional (default depends on dtype)",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Sampler of random data values with keyword arg "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "size"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". This function should take a single keyword argument "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "size"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " specifying the length of its returned ndarray. It is used to generate the nonzero values in the matrix after the locations of those values are chosen. By default, uniform [0, 1) random values are used unless "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "dtype"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is an integer (default uniform integers from that dtype) or complex (default uniform over the unit square in the complex plane). For these, the "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "rng"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is used e.g. "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "rng.uniform(size=size)"
                    },
                    {
                      "__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": "Returns a sparse array with the given shape and density where values are generated uniformly randomly in the range [0, 1)."
            }
          ]
        }
      ],
      "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/sparse/_construct.py",
  "item_line": 1397,
  "item_type": "function",
  "aliases": [
    "scipy.sparse.random_array"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "Passing a ``np.random.Generator`` instance for better performance:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nimport scipy as sp\nrng = np.random.default_rng()\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nDefault sampling uniformly from [0, 1):\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "S = sp.sparse.random_array((3, 4), density=0.25, rng=rng)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nProviding a sampler for the values:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "rvs = sp.stats.poisson(25, loc=10).rvs\nS = sp.sparse.random_array((3, 4), density=0.25,\n                           rng=rng, data_sampler=rvs)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "S.toarray()\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nProviding a sampler for uint values:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "def random_uint32_to_100(size=None):\n    return rng.integers(100, size=size, dtype=np.uint32)\nS = sp.sparse.random_array((3, 4), density=0.25, rng=rng,\n                           data_sampler=random_uint32_to_100)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nBuilding a custom distribution.\nThis example builds a squared normal from np.random:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "def np_normal_squared(size=None, rng=rng):\n    return rng.standard_normal(size) ** 2\nS = sp.sparse.random_array((3, 4), density=0.25, rng=rng,\n                           data_sampler=np_normal_squared)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nOr we can build it from sp.stats style rvs functions:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "def sp_stats_normal_squared(size=None, rng=rng):\n    std_normal = sp.stats.distributions.norm_gen().rvs\n    return std_normal(size=size, random_state=rng) ** 2\nS = sp.sparse.random_array((3, 4), density=0.25, rng=rng,\n                           data_sampler=sp_stats_normal_squared)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nOr we can subclass sp.stats rv_continuous or rv_discrete:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "class NormalSquared(sp.stats.rv_continuous):\n    def _rvs(self,  size=None, random_state=rng):\n        return rng.standard_normal(size) ** 2\nX = NormalSquared()\nY = X().rvs\nS = sp.sparse.random_array((3, 4), density=0.25,\n                           rng=rng, data_sampler=Y)\n",
        "execution_status": "success"
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "shape",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "density",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "0.01"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "format",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "coo"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "dtype",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "rng",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "data_sampler",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "random_state",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "None"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "random_array"
  },
  "references": null,
  "qa": "scipy.sparse._construct:random_array",
  "arbitrary": [],
  "local_refs": [
    "data_sampler",
    "density",
    "dtype",
    "format",
    "res",
    "rng",
    "shape"
  ]
}