1from array import *
2
3T = [[11, 12, 5, 2], [15, 6,10], [10, 8, 12, 5], [12,15,8,6]]
4for r in T:
5 for c in r:
6 print(c,end = " ")
7 print()
1def build_matrix(rows, cols):
2 matrix = []
3
4 for r in range(0, rows):
5 matrix.append([0 for c in range(0, cols)])
6
7 return matrix
8
9if __name__ == '__main__':
10 build_matrix(6, 10)
1# 5x6, 2-d array of booleans using list comprehension:
2
3matrix = [[False for col in range(6)] for row in range(5)]
4
5# 6x5, 2-d array of banana's using list comprehension:
6
7matrix = [['banana' for col in range(5)] for row in range(6)]
1# 2D arrays in python can be used to create rudimentary games
2
3array_2d = [['row0, column0'], ['row0, column1'], ['row0, column2'],
4 ['row1, column0'], ['row1, column1'], ['row1, column2'],
5 ['row2, column0'], ['row2, column1'], ['row2, column2']]
6
1length, breadth = x, y
2matrix = [[-1 for j in range(breadth)] for i in range(length)]
3# every element is -1