dumbledad
0
Q:

2d array in python

# Using above first method to create a  
# 2D array 
rows, cols = (5, 5) 
arr = [[0]*cols]*rows 
print(arr) 
3
# Using above second method to create a  
# 2D array 
rows, cols = (5, 5) 
arr = [[0 for i in range(cols)] for j in range(rows)] 
print(arr) 
0
def build_matrix(rows, cols):
    matrix = []

    for r in range(0, rows):
        matrix.append([0 for c in range(0, cols)])

    return matrix

if __name__ == '__main__':
    build_matrix(6, 10)
5
from array import *

T = [[11, 12, 5, 2], [15, 6,10], [10, 8, 12, 5], [12,15,8,6]]
for r in T:
    for c in r:
        print(c,end = " ")
    print()
2
for row in A:
    for val in row:
        print '{:4}'.format(val),
    print
0
import numpy as np
print(np.matrix(A))
0

New to Communities?

Join the community