Reputation: 631
I receive a RuntimeWarning: invalid value encountered in double_scalars
in the following code:
resident_specific_occupation_chances[iii] = (resident_specific_occupation_chances[iii]/summed)*((1-unemployment_chance)/1)
I don't really understand why this happens. I read a lot abut double scalar warnings, but it doesn't make sense to me.
Where does this error occur? On the left side of the equation while assigning a new value to my list item? Or on the right side during calculation?
I'm not using numpy here.
How can I prevent this? I don't want to disable the warnings.
I tried to reconstruct the issue in a simple form, but the warning does not occur:
test_list = [0.05, 0.2, 0.1, 0.3]
summed = sum(test_list[:3])
excluded = 0.3
for i in range(len(test_list)-1):
test_list[i] = (test_list[i]/summed)*((1-excluded)/1)
print(test_list)
>>>>[0.1, 0.4, 0.2, 0.3]
Upvotes: 1
Views: 9805
Reputation: 7744
The error is simply used to indicate a division where the denominator is of 0
value, e.g. your data somehow contains incorrect values, for example you try to take the square root of negative numbers, or 1/a where a (which is an array) contains zeroes.
RuntimeWarning: divide by zero encountered in double_scalars
I am not able to reproduce the same error from the code above, just like you mentioned so it's a bit hard for me to debug the exact problem.
My advice would be to debug your main code, stepping through line by line and understand the numerical operations that are taking place. You will then be able to tell at exactly where this occurs.
Upvotes: 2