Print An Identity Matrix In Python

Share on facebook
Share on twitter
Share on pinterest

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



Subscribe to our Newsletter

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

Share this post with your friends

Share on facebook
Share on google
Share on twitter
Share on linkedin

Leave a Reply

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