Skip to content

Instantly share code, notes, and snippets.

@naemazam
Created October 30, 2021 10:21
Show Gist options
  • Save naemazam/7ad00f690f005c1aba6f5aed22ae0bba to your computer and use it in GitHub Desktop.
Save naemazam/7ad00f690f005c1aba6f5aed22ae0bba to your computer and use it in GitHub Desktop.
'''
example
Enter your value:5
[[1. 0. 0. 0. 0.]
[0. 2. 0. 0. 0.]
[0. 0. 3. 0. 0.]
[0. 0. 0. 4. 0.]
[0. 0. 0. 0. 5.]] '''
import numpy as np
input_val = int(input('Enter your value:'))
x = np.zeros((input_val, input_val))
np.fill_diagonal(x, range(1,input_val+1))
print(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment