I am reading, processing and fitting some data that has been collected at different temperatures. For each set, the measured temperature oscillates a little so I have grouped the results by taking temperature averages. I then ask the user to select the temperatures of interest (discard noisy ones for instance) via raw_input, and use those indices to locate the data that will be fitted. The problem is that the float averaged numbers and those indicated by the user use different representations and therefore cannot be compared (see Python - round a float to 2 digits).
Below is an example of what my code does:
# Example of temperatures on my data set
T = [25.99545, 25.99702, 25.9982, 25.99859, 25.9986, 25.99899, 25.99899, 25.99899, 25.99899, 25.99899, 25.99899, 25.99938, 25.99938, 26.00016, 26.00056, 26.00056, 26.00056, 26.00056, 26.00056, 26.00095, 26.00095, 26.00095, 26.00134, 26.00134, 26.00134, 26.00174, 26.00213, 26.00252, 27.998, 27.99846, 27.99846, 27.99891, 27.99891, 27.99891, 27.99935, 27.99935, 27.99936, 27.9998, 27.9998, 27.9998, 27.99981, 27.99981, 28.00025, 28.00025, 28.00026, 28.00026, 28.0007, 28.0007, 28.0007, 28.0007, 28.00114, 28.00115, 28.00115, 28.00115, 28.00204, 28.00249, 29.99771, 29.99822, 29.99822, 29.99822, 29.99873, 29.99873, 29.99873, 29.99923, 29.99923, 29.99924, 29.99974, 29.99974, 29.99975, 29.99975, 29.99975, 30.00026, 30.00026, 30.00026, 30.00026, 30.00076, 30.00076, 30.00127, 30.00127, 30.00178, 30.00178, 30.00178, 30.00229, 30.00229, 31.99801, 31.99858, 31.99858, 31.99858, 31.99858, 31.99858, 31.99916, 31.99916, 31.99916, 31.99916, 31.99973, 32.00029, 32.0003, 32.0003, 32.0003, 32.0003, 32.0003, 32.00086, 32.00086, 32.00087, 32.00087, 32.00143, 32.00143, 32.00143, 32.002, 32.00201, 32.00257, 32.00372 ]
av_T = [ 25.999885000000003, 28.000059642857156, 30.000000357142863, 32.000254285714284 ] # Average of temperatures
rounded_T = [ round(x,2) for x in av_T ]
selected_T = [ 26.0, 30.0 ] # User selection of temperatures
if selected_T not in rounded_T: # Check the user indicates valid temperatures
print('The selected temperature is not in your experimental set')
exit()
Since their representation cannot be compared, my code gets stuck at this point always. Also, note that even if I don't round the av_T and
selected_T = [ 25.999885000000003, 30.000000357142863 ]
I get the same behaviour. Is there a way to make this comparison without resorting to decimal precision?