Skip to content

Instantly share code, notes, and snippets.

@naemazam
Created October 30, 2021 08:24
Show Gist options
  • Save naemazam/3fdd211347fd7e2d61a9fcf3a09c7998 to your computer and use it in GitHub Desktop.
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
'''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