Header Ads

Python - WAP to Print the Identity Matrix in Python - 12



This is a Python Code to print the Identity Matrix of any given Number using Python.

Source Code:
#!/usr/bin/Python3

num = int(input(" Enter a Number : "))

print ("Matrix :")
for idx in range(0, num):
    for jdx in range (0, num):
        if ( idx == jdx):
            print (" 1", sep=" ", end=" ")
        else:
            print (" 0", sep=" ", end=" ")
    print()


Program Output:


No comments