0
How to create multidimensional arrays in python ?
3 ответов
+ 1
To create a multidimensional list you simply create lists inside a list, some examples:
[ [20, 50], [2, 8], [9, 9] ]
[ [30, 87], [7], 10]
[ [ ] ]
[ [500, 600], [ [60, 61, 62], [73, 74, 75] ] ]
+ 3
For creating a m×n matrix:
a=[]
for i in range(m):
a.append([])
for j in range(n):
a[i].append(j)
print(a)
but working with numpy is more efficient.
+ 3
I like to use comprehensions.
Let's say 2d array of zeros 10x10:
arr = [
[0 for j in range(10)]
for i in range(10)
]
If you want to output:
for row in arr:
print(*row)