Feature request: numpy.random.normal with `dtype`
See original GitHub issueWhen constructing arrays it is useful to set the dtype. For some reason we can do it with some np.random
methods such as random integers but not with random normal values. Could we have a consitent version across all methods that generate new np.arrays?
>>> np.random.randint(10,dtype="Int16")
9
>>> np.random.normal(10,dtype="Float32")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "mtrand.pyx", line 1547, in mtrand.RandomState.normal (numpy/random/mtrand/mtrand.c:20493)
TypeError: normal() got an unexpected keyword argument 'dtype'
This would be nice in order to avoid np.array( somearray, dtype=sometype )
every time we create a new random array.
For example
np.array( np.random.normal(10), dtype="Float32")
could be simply written as
np.random.normal(10, dtype="Float32")
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:13 (9 by maintainers)
Top Results From Across the Web
numpy.random.normal — NumPy v1.24 Manual
Draw random samples from a normal (Gaussian) distribution. The probability density function of the normal distribution, first derived by De Moivre and 200...
Read more >Supported NumPy features - Numba
NumPy dtypes provide type information useful when compiling, and the regular, ... Numba supports top-level functions from the numpy.random module, ...
Read more >tf.random.normal | TensorFlow v2.11.0
Outputs random values from a normal distribution. ... Watch on demand ... mean, A Tensor or Python value of type dtype , broadcastable...
Read more >Can I specify a numpy dtype when generating random values?
numpy will automatically convert the type of your random array to the type of x when you do the operation in-place, there's absolutely...
Read more >Chapter 4. NumPy Basics: Arrays and Vectorized Computation
Since NumPy is a large topic, I will cover many advanced NumPy features like ... function in numpy.random to generate some random normally...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Use randomgen until the new PRNG infrastructure gets into NumPy (hopefully this year). 32 bit is supported for the most common types (normal, exponential, uniform and gamma).
I would like to re-open the issue, as I keep bumping into wanting this almost weekly for over a year. The conversion is not a solution, because most of the times I need this it is for memory purposes. It seems to be a somewhat common request, see for example this SO question about it (not me), and the proposed workaround.