I want to create for example n matrices like:
m1 = [[0,0],[0,0]]
m2 = [[0,0],[0,0]]
.
.
mn = [[0,0],[0,0]]
1 Answer 1
I think that will work for you
res = [[[0 for item3 in range(2)] for item2 in range(2)] for item1 in range(10)]
print res
Output:
[
[[0, 0], [0, 0]],
[[0, 0], [0, 0]],
[[0, 0], [0, 0]],
[[0, 0], [0, 0]],
[[0, 0], [0, 0]],
[[0, 0], [0, 0]],
[[0, 0], [0, 0]],
[[0, 0], [0, 0]],
[[0, 0], [0, 0]],
[[0, 0], [0, 0]]
]
Basically 10(your n value) arrays with 2x2 lists of zeros.
answered Jul 22, 2015 at 17:42
omri_saadon
10.8k8 gold badges36 silver badges58 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py
res = [[item for item in range(2)] for item in range(10)]lists of[0, 1], not[0, 0]. It also has the wrong dimensions (10x2 instead of nx2x2).