Member 13506386 Ответов: 1

Как итеративно заменить значения в одном списке списков на основе другого списка списков в Python


I am a python new bie.  
I have two list of lists like this:  

    A = List[List[float,float]]   
    B = List[List[float,float]]  

 
both different sizes
Ex :   

    A has [time, value]  
    B has [start_time, end_time]  

 
    A = [[0.0,10.0] , [1.0,10.0], [2.0,10.0], [3.0,10.0], [4.0,10.0],  [5.0,10.0],  [6.0,10.0]]
    B = [[0.0,2.0], [5.0,6.0]]     
    


What I am trying to do is :  
 if A has a time which is not in B, I should make the corresponding 'value' in A to zero. 

So output would be : 

    [[0.0,10.0] , [1.0,10.0], [2.0,10.0], [3.0,0.0], [4.0,0.0],  [5.0,10.0],  [6.0,10.0]]
  i.e if a time segment in B has no corresponding time value present in A, the value corresponding to that time should be made zero. In this case, the values between 2 and 5 are there in B , so  partner values of'3' and '4' in A are made to zeroes.


Please tell me how to do it.


Что я уже пробовал:

Я ничего не понимаю.


AA = numpy.hstack(B) # для получения массива времен
для i в 1: len(AA):
если (AA[i]==A[

1 Ответов