1
Good night I’m having a hard time with this:
[['1', 0.0, 1.8], ['1', 3.0, 2.0], ['1', 5.0, 1.5], ['1', 6.0, 1.5], ['1', 9.0, 3.0], ['2', 0.0, 1.8], ['2', 1.0, 1.5], ['2', 2.0, 1.5], ['2', 3.0, 2.0], ['2', 8.0, 2.1], ['3', 0.0, 1.8], ['3', 1.0, 2.0], ['3', 4.0, 1.5], ['3', 8.0, 1.5], ['3', 9.0, 1.5], ['4', 0.0, 1.8], ['4', 1.0, 1.5], ['4', 2.0, 2.0], ['4', 3.0, 2.0], ['4', 4.0, 2.0]]
I want to find the values of the equal rows and find the arithmetic medias of the other two values..
the output of my code should be like this
[['1',4.6,1.96],['2',2.8,1.78],['3',4.4,1.66],['4',2,1.86]]
for example for the values of fila[0]==1
, to find the average of these values should be added the values (0.0+3.0+5.0+6.0+9.0)
and divide them by the amount of them,5.
I cannot properly traverse this matrix to make the right condition to find the result matrix...
I went to the first list with this code but I can only find the medias of the valuables that contain as the first element to str '1'...
suma = 0
lista2=[]
for n in range (len(lista)-1):
if lista[n][0]==lista[n][0]:
lista2.append(lista[n][0])
suma= suma+lista[n][1]
if lista[n][0]!=lista[n+1][0]:
break
print (suma)
#print(len(lista2))
print(suma/len(lista2))
it has to be that way?
– Tmilitino
yes the result has to be in the form of lists again, ie as a matrix...
– Fernando Alvarez Saucedo