Write a Python function to Print an Identity Matrix


Topic: Write a Python function to Print an Identity Matrix

Solution

def print_identity_matrix(n):
    for i in range(0,n):
        for j in range(0,n):
            if(i==j):
                print("1",sep=" ",end=" ")
            else:
                print("0",sep=" ",end=" ")
        print()



List all Python Programs