为python中的值选择正确的时间间隔

我有一个排序数字列表,被视为间隔列表,称为间隔

intervals

array([[0.0417634 ],
   [0.05653888],
   [0.02597058],
   [0.01339346],
   [0.0133483 ],
   [0.24812345],
   [0.27849978],
   [0.2663314 ],
   [0.3343273 ],
   [0.41353753],
   [0.54377884],
   [0.5509521 ],
   [0.77681744],
   [0.88761437]], dtype=float32)

称为值的值列表

values

array([0.04335092, 0.04767257, 0.04411646, 0.04539008, 0.04223311,
   0.05031073, 0.05701819, 0.06020058, 0.05755847, 0.05762227,
   0.05823819, 0.05744556, 0.04815019, 0.03788265, 0.03679871,
   0.03749876, 0.0326803 , 0.02657353, 0.02507633, 0.01827177,
   0.01111718, 0.00213232, 0.00432787, 0.00422399, 0.00907576,
   0.01227452, 0.01389197, 0.0089301 , 0.00909326, 0.01107823,
   0.01505833, 0.01397665, 0.01433514, 0.01372994, 0.01350524,
   0.01616598, 0.01424029, 0.01416126, 0.01585266, 0.01563135,
   0.01521641, 0.01602485, 0.01577531, 0.0212718 , 0.02273118, dtype=float32)

和称为字母的符号列表

letters

['a', 'b','c', 'd',...,'z','aa','ab','ac',....,'az','ba','bb','bc'.........'zz']

间隔的每个元素都映射有一个符号,例如

intervals[0] = 'a'
intervals[1] = 'b'
.....

现在,我想创建一个新列表,以正确的间隔映射值的每个元素,并为其分配正确的符号。

enter image description here

例:

if(values[i] < intervals[0]):
    newarray[i] = letters[0]

要么

if(values[i] > intervals[j] and values[i] < intervals[j+1]:
    newarray[i] = letter[k]

最终输出

['c','x','a','aa','br'...]
评论