0

How to create multidimensional arrays in python ?

2nd Nov 2019, 9:34 AM
Rajan K
Rajan K - avatar
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] ] ]
2nd Nov 2019, 11:20 AM
Seb TheS
Seb TheS - avatar
+ 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.
2nd Nov 2019, 11:09 AM
Qasem
+ 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)
2nd Nov 2019, 11:25 AM
HonFu
HonFu - avatar