question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dtype keyword for np.random.randint and np.random.rand

See original GitHub issue

As brought up at the mailinglist, this code ates up much memory:

spectrumArray = np.random.randint(0,255, (2**20,2**12)).astype(np.uint8)

It has also crossed my mind that np.random.randint and np.random.rand could use an extra ‘dtype’ keyword. It didn’t look easy to implement though.

See this thread on the mailinglist: [Numpy-discussion] array of random numbers fails to construct

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:29 (21 by maintainers)

github_iconTop GitHub Comments

3reactions
charriscommented, Jan 3, 2016

Someone might want floats instead of doubles, that would about double the speed.

0reactions
mattipcommented, May 29, 2019

Closing, the new API supports dtype. Please reopen if needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

numpy.random.randint — NumPy v1.24 Manual
Return random integers from the “discrete uniform” distribution of the specified dtype in the “half-open” interval [low, high). If high is None (the ......
Read more >
Can I specify a numpy dtype when generating random values?
Q: is it possible to specify a dtype for random numbers when I create them. A: No it isn't. randn accepts the shape...
Read more >
Random sampling in numpy | randint() function - GeeksforGeeks
numpy.random.randint() is one of the function for doing random sampling in numpy. It returns an array of specified shape and fills it with ......
Read more >
How to Use NumPy random.randint() in Python
NumPy random.randint() function in Python is used to return random integers from the values specified with low (inclusive) to high ...
Read more >
Random Number Generator Using Numpy Tutorial - DataCamp
Random Number Generator Using Numpy Tutorial · import numpy as np np.random. · array([0.3745012, 0.95071431, 0.73199394, 0.59865848]) · heads = random_numbers < ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found