Write a program to create zero matrix


Topic: Write a program to create zero matrix

Solution

rows = 2
cols = 3
M = []
while len(M) < rows:
    M.append([])
    while len(M[-1]) < cols:
        M[-1].append(0.0)
print("Zero Matrix")
for i in range(rows):
    row = '|'
    for b in range(cols):
        row = row + ' ' + str(M[i][b])
    print(row + ' ' + '|')



List all Python Programs