0

print(l) gives the right output, but none of the numpy functions do in the first "loop" of the loop.

from numpy import mean, max, min


table = [[0] * 3] * 2
for i, l in enumerate([[1, 2, 3], [4, 5, 6]]):
    print(l)
    table[i][0] = mean(l)
    table[i][1] = max(l)
    table[i][2] = min(l)
print(table)

When i run it i get:

[1, 2, 3]

[4, 5, 6]

[[5.0, 6, 4], [5.0, 6, 4]]

Expected:

[1, 2, 3]

[4, 5, 6]

[[2.0, 3, 1], [5.0, 6, 4]]

I suspect something weird is happening with the nested list because i tried print(mean(l)) (instead of print(l)) and that gave the correct mean, but i see no reason for it not working when assigning values to the table.

0 Answers0