Print An Identity Matrix In Python

In this Basic Python Program, we will have a look at how to “print an Identity Matrix” with the help of Python Programming Language.

Python Program To Print An Identity Matrix

n=int(input("Enter a number: "))

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()

In the above basic python program, we read a number n and print an identity matrix of the desired size



Leave a Reply

Your email address will not be published. Required fields are marked *

Shopping cart