我想创建一个具有不同bin大小和增量的bin值字典。例如,
Starting increment is 5, through 10 (e.g. 0-5, 6-10)
Then, increments of 10, through 100 (e.g. 11-20, 21-30...91-100)
Then increments of 25, through 200 (e.g. 101-125, 126-150...176-200)
在词典中,
bin_dict = {0-10 :[0-5, 6-10], 10-100:[11-20, 21-30, ...91-100], 100-200:[101-125, 126-150..]}
我尝试了以下代码:
def create_bin_ranges(bn_val):
## Create a list of bin ranges.
dict_bin_ranges = {}
list_bin_ranges = []
for i in bn_val:
step = i
bin_range = np.arange(0, step+i, step)
list_bin_ranges.append(bin_range)
dict_bin_ranges[i] = list_bin_ranges
return dict_bin_ranges
我得到的结果是:(这不是我想要的)
values = create_bin_ranges([5,10,100])
print(values)
>> {5: [array([0, 5]), array([ 0, 10]), array([ 0, 100])],
10: [array([0, 5]), array([ 0, 10]), array([ 0, 100])],
100: [array([0, 5]), array([ 0, 10]), array([ 0, 100])]}
我被困住了,任何建议或帮助都会很棒。