Created
October 30, 2021 08:24
-
-
Save naemazam/3fdd211347fd7e2d61a9fcf3a09c7998 to your computer and use it in GitHub Desktop.
Create a 4 * 4 matrix with values of 1,2,3,4 on the main diagonal of the array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''Create a 4 * 4 matrix with values of 1,2,3,4 on the main diagonal of the | |
array. The legend is as follows: | |
Input: 4 | |
Output: | |
[[1. 0. 0. 0.] | |
[0. 2. 0. 0.] | |
[0. 0. 3. 0.] | |
[0. 0. 0. 4.]] | |
''' | |
import numpy as np | |
x = np.diag([1, 2, 3, 4]) | |
print(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment