0

i have a list of sorted numbers that is seen as a list of intervals, called intervals

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)

a list of values called values

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)

and a list of symbols called letters

letters

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

each element of intervals is mapped with a symbol, ex

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

now i want to create a new list that map each element of values in the right interval and assign to it the right symbol.

enter image description here

example:

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

or

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

with final output

['c','x','a','aa','br'...]
Fabio G
  • 29
  • 7
  • Does this do what you want? `letters[np.searchsorted(intervals.ravel(), values)]` Make sure `letters`is a numpy array too – yatu Feb 07 '20 at 11:55
  • @yatu IndexError: index 35 is out of bounds for axis 1 with size 35 – Fabio G Feb 07 '20 at 12:03

0 Answers0