Aug-04-2018, 12:03 AM
(Aug-03-2018, 08:06 PM)Vysero Wrote:(Aug-03-2018, 07:53 PM)amyvaulhausen Wrote: what I essentially need
is to find out how to perform this kind of function on approximate numbers that are with a
range of say +,- 10 values difference but also allows for decimal values
If you have a range of decimal values which are acceptable then I would suggest you round them:
from statistics import mode new_list = [] x = [12,11,10.4,12,10.3,10.4,15] for y in x: new_list.append(round(y)) print('new_list = ', new_list, 'mode of new_list = ', mode(new_list))Output:
new_list = [12, 11, 10, 12, 10, 10, 15] mode of new_list = 10Is that acceptable or must you keep the decimal values?
Thank you sir, I honestly appreciate the kind feedback! :) In my situation, I need a
mode like function but I do not think mode will work here. I wish this were the case.
Ideally, it would be great if decimals could be retained, but it would be ok if we had
to lose these. The problem however comes, where I am dealing with randomized data
except that often numeric trends of similar magnitudes will occur in a set. It is the
values of similar magnitude I want to capture. So for example if out of ten numbers,
three of these values are close to, for example, 300 but may range up or down by say
ten, then I want to grab these values. So for example ; 299, 308, 303 have similiar
magnitudes but because they are not exact, mode wont return them if I understand correctly.
I like your suggestion however, wondering, do you think some kind of simple iterative
loop that checks and compares each number to all other numbers with an IF style statement
checking upper, lower bounds of number value within +,- 10 would work ok, or is there
a simpler way?