Skip to content

ENH: Add optional dtype parameter to Generator's distribution methods #26779

@chimaerase

Description

@chimaerase

Proposed new feature or change:

Many np.random.Generator distribution methods generate floating point arrays, but don't accept a dtype parameter to control the desired precision. As a result, the generated arrays have limited utility in some situations, or for downcasting, have to be reconstructed afterward with the desired precision. For example, standard_exponential() has a dtype parameter, but uniform() doesn't. Providing intentionally-typed float parameters to uniform() still doesn't affect the output dtype (always np.float64)

>>> rng = np.random.default_rng(42)
>>> result = rng.uniform(np.float32(0.0), np.float32(10), 20)
>>> result.dtype
dtype('float64')

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions