I have 2 lists distance_boundary and distance
distance_boundary = [100,200,300]
distance = [125,255,285,140,160,180]
Now I want to create a new variable floor and I want to assign the value for floor based on the distance value and it is defined by distance_boundary
For example ,
distance[0] is 125
since this is between distance_boundary[0] and distance_boundary[1] so the corresponding value for floor should be 1
distance[1] is 255
since this is between distance_boundary[1] and distance_boundary[2] so the corresponding value for floor should be 2
Looping through this should give me the final value of floor as
floor = [1,2,2,1,1,1]
I tried to loop through distance and used to np.where for assignment
floor = []
for j in range(0,len(distance)):
floor = (np.where((distance[j]>distance_boundary[0]) & (distance[j]>distance_boundary[1]))
,1,2)
floor.append(floor)
This is not giving me desired result and moreover it is not looking scalable. Is there any other better solution