I have this list of lists:nc = [[1, 2], [1, 1], [-1, 1], [2, 3], [10, 0], [0, 30], [0, 0]]
I also have this list of lists: 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]]]
Now i want to create a 3rd list of lists named pref_indic that will check the nc[3] which is [2, 3] with a for loop, it will check with an if whether the type is 2 or 3. Then it will make mathematical operations for each type. I have the code below:
#calculation of preference indicator
pref_indic = []
for x in range(len(crt)):
if (nc[3][x] == 2):
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 type is 2 then i want to append to a 3rd list of lists with aces and zeros, if the value of DivMatrix is <=0 it will append 0, else 1. For type 3 it will make other mathematical operations. At the moment i want to make the first type. len(crt)=2
Aucun commentaire:
Enregistrer un commentaire