- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create an identity matrix using Numpy?
In this program, we will print an identity matrix of size nxn where n will be taken as an input from the user. We shall use the identity() function in the numpy library which takes in the dimension and the data type of the elements as parameters
Step 1: Import numpy. Step 2: Take dimensions as input from the user. Step 3: Print the identity matrix using numpy.identity() function.
import numpy as np dimension = int(input("Enter the dimension of identitiy matrix: ")) identity_matrix = np.identity(dimension, dtype="int") print(identity_matrix)
Enter the dimension of identitiy matrix: 5 [[1 0 0 0 0] [0 1 0 0 0] [0 0 1 0 0] [0 0 0 1 0] [0 0 0 0 1]]
- Python PyTorch – How to create an Identity Matrix?
- Python Program to Print an Identity Matrix
- Golang Program to Print an Identity Matrix
- Return the identity array in Numpy
- Program for Identity Matrix in C
- How to create an empty matrix in R?
- How to create an upper triangular matrix using vector elements in R?
- How to create a block diagonal matrix using a matrix in R?
- How to create an image of matrix of pixels in R?
- How to create an Arc using JavaFX?
- How to create an Ellipse using JavaFX?
- How to create an HBox using JavaFX?
- How to create an VBox using JavaFX?
- Create an array with zero above the main diagonal forming a lower triangular matrix in Numpy