Complete the code to create a 3x3 identity matrix using numpy.
import numpy as np matrix = np.[1](3) print(matrix)
The np.eye() function creates an identity matrix of given size.
Complete the code to create a 4x4 identity matrix with float type values.
import numpy as np matrix = np.eye(4, dtype=[1]) print(matrix)
The dtype parameter sets the data type of the matrix elements. For decimal numbers, use float.
Fix the error in the code to create a 5x5 identity matrix with numpy.
import numpy as np matrix = np.eye([1]) print(matrix)
The size parameter must be an integer without quotes. Using quotes makes it a string, causing an error.
Fill both blanks to create a 3x5 identity-like matrix with ones on the diagonal.
import numpy as np matrix = np.eye([1], [2]) print(matrix)
The first parameter is the number of rows (3), the second is the number of columns (5) for a rectangular identity matrix.
Fill all three blanks to create a 4x4 identity matrix with ones on the diagonal shifted by 1 above the main diagonal.
import numpy as np matrix = np.eye([1], [2], k=[3]) print(matrix)
The first two parameters set the size (4x4). The k=1 shifts the diagonal of ones one position above the main diagonal.