Im working on geological datasets and am trying to smooth the data distribution to improve the machine learning algorithms.
I need to calculate the error on certain values by using half of their last decimal, just like most measuring instruments recommend.
Here are some examples of what I would like to obtain from certain numbers:
0.010 -> 0.005
0.020 -> 0.005
0.090 -> 0.005
0.100 -> 0.05
0.600 -> 0.05
0.900 -> 0.05
Cheers!
Convert the value to a string. Count the zeros and use '0.' + num_zeros * '0' + '5'
to get the new number as a string. Convert the string to a float.
def half_of_last_non_zero_digit(num):
return float('0.' + '0' * len(str(num).split('.')[1]) + '5')
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments