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.

multinomial casts input to np.float64

See original GitHub issue

np.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:closed
  • Created 7 years ago
  • Reactions:8
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
olfMombachcommented, Mar 31, 2021

I don’t really see how that fixes the problem

2reactions
leachimcommented, Nov 7, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >
tf.cast | TensorFlow v2.11.0
Casts a tensor to a new type.
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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