multinomial casts input to np.float64
See original GitHub issuenp.random.multinomial
seems to cast its second argument pvals
to an array of dtype float64. Whilst this isn’t an issue in and of itself, I’ve come across an interesting scenario where I have an array of dtype float32 whose sum is 0.99999994
, and when it gets cast to float64, its sum is now 1.0000000222053895
, which causes np.random.multinomial
to raise ValueError: sum(pvals[:-1]) > 1.0
.
For a little context, I have an array of dtype float32 because it’s come off the GPU, where single precision calculations are a great deal faster.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:8
- Comments:15 (6 by maintainers)
Top Results From Across the Web
Numpy.dot TypeError: Cannot cast array data from dtype ...
python - Numpy. dot TypeError: Cannot cast array data from dtype('float64') to dtype('S32') according to the rule 'safe' - Stack Overflow. Stack Overflow...
Read more >Chapter 4. NumPy Basics: Arrays and Vectorized Computation
Since NumPy is focused on numerical computing, the data type, if not specified, will in many cases be float64 (floating point). Table 4-1....
Read more >Python Examples of numpy.float64 - ProgramCreek.com
This page shows Python examples of numpy.float64.
Read more >Learn Numpy by Playing — Concepts, Indexing, Vectorization ...
Data Types and Casting. Notes. Numpy array can store items of only one data type; np_array.dtype attribute will give dtype of the array;...
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 FreeTop 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
Top GitHub Comments
I don’t really see how that fixes the problem
I happened to run into this issue today. Wondering whether there is any reason for casting the array to float64? This should probably be fixed in numpy itself.