floating-point-precision

Can I specify a numpy dtype when generating random values?

Can I specify a numpy dtype when generating random values? Question: I’m creating a numpy array of random values and adding them to an existing array containing 32-bit floats. I’d like to generate the random values using the same dtype as the target array, so that I don’t have to convert the dtypes manually. Currently …

Total answers: 3

How to avoid floating point errors?

How to avoid floating point errors? Question: I was trying to write a function to approximate square roots (I know there’s the math module…I want to do it myself), and I was getting screwed over by the floating point arithmetic. How can you avoid that? def sqrt(num): root = 0.0 while root * root < …

Total answers: 2

Python: Find index of minimum item in list of floats

Python: Find index of minimum item in list of floats Question: How can I find the index of the minimum item in a Python list of floats? If they were integers, I would simply do: minIndex = myList.index(min(myList)) However, with a list of floats I get the following error, I assume because float equality comparison …

Total answers: 4