本文介绍了如何基于Python中的另一个列表列表迭代替换一个列表列表中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是一个蟒蛇新bie。 我有两个列表如下: A = List [List [float,float]] B = List [List [float,float]] 两种不同尺码 Ex: A有[时间,价值] B有[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]] 我想做的是:如果A有一个不在B的时间,我应该把A中相应的'值'设为零。 因此产出将是: [[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]] 即如果B中的时间段在A中没有相应的时间值,则对应于该时间的值应为零。在这种情况下,B中存在2到5之间的值,因此A中的'3'和'4'的伙伴值被设为零。 请告诉我该怎么做。
我试过的: 我很无能为力。 AA = numpy.hstack(B)#获取次数 for i in 1:len(AA): if(AA [i] == A [
解决方案Python教程 - Python 3.4.7文档 [ ^ ] 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.
What I have tried: I'm an clueless. AA = numpy.hstack(B) # for getting array of times for i in 1: len(AA): if (AA[i]==A[
解决方案 The Python Tutorial — Python 3.4.7 documentation[^]更多推荐
如何基于Python中的另一个列表列表迭代替换一个列表列表中的值
发布评论