Python and nested lists problem
I have a matrix with 5 rows and 4 cols containing some numbers. I need to take each row, do an average from the first and second col, and another average from the third and fourth col, subtract these numbers from a constant and put these in another matrix, which will then have 5 rows and 2 cols.
Here's the code that I coined up, but it counts nonsenses: Code:
vrch=624 Here's the output: Code:
0 [112.5, 231.0] |
In the loop you are assigning the list ins to all rows in delky.
Since a list is an object (not a primitive type, like e.g. an integer), all delky[i] will become a reference to ins. But the contents of ins change each time the loop runs. So all delky[i] will refer to the same ins! A bit difficult to explain. But try this smaller program and see what happens in the last part: Code:
delky = [[0,0], [0,0], [0,0]] Code:
delky = [[0,0], [0,0], [0,0]] Code:
vrch=624 Code:
vrch=624 |
Very well, thank you for the explanation! Now it works fine..
|
All times are GMT -5. The time now is 11:34 AM. |