某些操作后如何更新python数组

时间:2018-09-25 06:34:48

标签: python numpy

在下面的代码中,我有一个名为int totalCumilation = 100; //adding values of all item should equal to this. User might give 100 to 100000 int numberOfItems = 3; //User might give 2..25 Solver solver = new Solver("MY_CP"); IntVar[] weights = solver.makeIntVarArray(numberOfItems, 0, totalCumilation, "weights"); solver.addConstraint(solver.makeEquality(solver.makeSum(weights), totalCumilation)); DecisionBuilder decisionBuilder = solver.makeDefaultPhase(weights); solver.solve(decisionBuilder); while (solver.nextSolution()) { for (int i = 0; i < weights.length; i++) { System.out.println(weights[i]); } System.out.println(""); } System.out.println("Finished"); 的数组。当for循环第一次运行时,我对该数组的一些值进行了切片,并创建了一个名为List的新数组。现在,我想将new替换为List,以便当for循环第二次运行时,它将从new而不是从new分割值。那我该怎么办呢?

List

这是结果

def update():
    low =[1.5, 2.5, 3.0]
    high = [4.0, 4.5, 5.0]
    for i in range(len(low)):
        h1 = low[i]
        h2 = high[i]
        List=np.arange(1.0, 5.01, 0.5)
        hList =[]
        for k in range(len(List)):
            hList.append(round(List[k],2))

        low_ind =hList.index(low[i])
        high_ind = hList.index(high[i])
        #Slicing
        List = List[low_ind:high_ind]``

1 个答案:

答案 0 :(得分:0)

不确定要做什么,但添加以下行:

        #Slicing
        new = List[low_ind:high_ind]
        List = new #This line

似乎要更新列表。