I have a list of numbers that I wish to somehow convert to unit step form
These are the boundaries I have
[367.3090551181102, 371.73179133858264, 376.1545275590551, 380.5772637795276, 385.0]
This is the data I have
[367.3090551181102, 370, 370, 370, 370, 370, 370, 370, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 368, 369, 368, 368, 368, 368, 368, 368, 368, 368, 369, 370, 367.3090551181102, 367.3090551181102, 367.3090551181102, 370, 368, 373, 369, 371, 368, 367.3090551181102, 367.3090551181102, 367.3090551181102, 369, 367.3090551181102, 372, 367.3090551181102, 368, 368, ...]
What I want to do is to basically round every number in the data down or up to the boundary. The number is between lower boundary and upper boundary.
Assume that the number is 370, I want to round this to 371.73... since it is between 367.309... and 371.73... or the number is 381, then i want to round it to 370.57...
This is the code I have but i am bit confused
def unit_step(data,boundaries):
us = []
for d in data:
if(boundaries[0] < d < boundaries[1]):
us.append(rounder(boundaries[0],boundaries[1],d))
elif(boundaries[1] < d < boundaries[2]):
us.append(rounder(boundaries[1],boundaries[2],d))
elif(boundaries[2] < d < boundaries[3]):
us.append(rounder(boundaries[2],boundaries[3],d))
elif(boundaries[3] < d < boundaries[4]):
us.append(rounder(boundaries[3],boundaries[4],d))
return us
I tried for loop inside another for loop but couldn't make it.
Where am i wrong or is it a useful approach compared to double for loop?