I created a list to represent a 2-dim matrix:
mylist = []
while (some condition):
x1 = ...
x2 = ...
mylist.append([x1,x2])
I would like to test if each entry in the second column of the matrix is bigger than 0.45, but I meet some difficulty:
>>> mylist
[[1, 2], [1, -3], [-1, -2], [-1, 2], [0, 0], [0, 1], [0, -1]]
>>> mylist[][1] > 0.4
File "<stdin>", line 1
mylist[][1] > 0.4
^
SyntaxError: invalid syntax
>>> mylist[:,1] > 0.4
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: list indices must be integers, not tuple
Given that mylist
is a list of sublists, how can I specify all the second components of all its sublists?
Is it good to choose list to represent the 2-dim matrix? I chose it, only because the size of the matrix is dynamically determined. What would you recommend?
Thanks!