jeudi 25 août 2016

How to append values to a list of lists using other list of lists and doing mathematical operations

i have a list of lists named crt = [[80, 90, 6, 5.4, 8, 5], [65, 58, 2, 9.7, 1, 1], [83, 60, 4, 7.2, 4, 7], [40, 80, 10, 7.5, 7, 10], [52, 72, 6, 2, 3, 8], [94, 96, 7, 3.6, 5, 6]],

another one named nc = [[1, 2, 3, 4, 5, 6], [1, 1, 1, 1, 1, 1], [-1, 1, -1, -1, -1, 1], [2, 3, 5, 6, 1, 6], [10, 0, 0.5, 1, 0, 0], [0, 30, 5, 3, 0, 0], [0, 0, 0, 0, 0, 5]]

and one last named DivMatrix = [[[0, -15, 3, -40, -28, 14], [15, 0, 18, -25, -13, 29], [-3, -18, 0, -43, -31, 11], [40, 25, 43, 0, 12, 54], [28, 13, 31, -12, 0, 42], [-14, -29, -11, -54, -42, 0]], [[0, 32, 30, 10, 18, -6], [-32, 0, -2, -22, -14, -38], [-30, 2, 0, -20, -12, -36], [-10, 22, 20, 0, 8, -16], [-18, 14, 12, -8, 0, -24], [6, 38, 36, 16, 24, 0]], [[0, -4, -2, 4, 0, 1], [4, 0, 2, 8, 4, 5], [2, -2, 0, 6, 2, 3], [-4, -8, -6, 0, -4, -3], [0, -4, -2, 4, 0, 1], [-1, -5, -3, 3, -1, 0]], [[-0.0, 4.299999999999999, 1.7999999999999998, 2.0999999999999996, -3.4000000000000004, -1.8000000000000003], [-4.299999999999999, -0.0, -2.499999999999999, -2.1999999999999993, -7.699999999999999, -6.1], [-1.7999999999999998, 2.499999999999999, -0.0, 0.2999999999999998, -5.2, -3.6], [-2.0999999999999996, 2.1999999999999993, -0.2999999999999998, -0.0, -5.5, -3.9], [3.4000000000000004, 7.699999999999999, 5.2, 5.5, 0, 1.6], [1.8000000000000003, 6.1, 3.6, 3.9, -1.6, -0.0]], [[0, -7, -4, -1, -5, -3], [7, 0, 3, 6, 2, 4], [4, -3, 0, 3, -1, 1], [1, -6, -3, 0, -4, -2], [5, -2, 1, 4, 0, 2], [3, -4, -1, 2, -2, 0]], [[0, 4, -2, -5, -3, -1], [-4, 0, -6, -9, -7, -5], [2, 6, 0, -3, -1, 1], [5, 9, 3, 0, 2, 4], [3, 7, 1, -2, 0, 2], [1, 5, -1, -4, -2, 0]]]

I want to create a list of lists with the same size as DivMatrix. The creation must start with a for loop and then with 6 different if statements, each one of them representing a type equation with nc[3]. I want to build the first if statement and then i will build the others which are more complicated.I have this algorithm so far but it is wrong.

pref_indic = []
for x in range(len(crt)):
    if (nc[3][x] == 1):
    prolist = []
    for y in range(len(DivMatrix[x])):
        prolist2 = []
        for z in range(len(DivMatrix[x])):
            if (DivMatrix[y][z]<=0):
                prolist2.append(0)
            else:
                prolist2.append(1)
            prolist.append(prolist2)
    pref_indic.append(prolist)
else:
    print "wrong function type"


print pref_indic

If the nc[3][x] = 1 which means if the type is type 1, then if the value in DivMatrix[x]<=0 then append 0, else append 1.

So as a result, for nc[3][4] which is equal to 1, i will get the following list appended pref_indic[4] = [[0, 0, 0, 0, 0, 0],[1, 0, 1, 1, 1, 1],[1, 0, 0, 1, 0, 1],[1, 0, 0, 0, 0, 0],[1, 0, 1, 1, 0, 1],[1, 0, 0, 1, 0, 0]]

sorry for the size of the post.

Aucun commentaire:

Enregistrer un commentaire