np diag
x = [0, 4, 8]
print(np.diag(x))
# Output:
[[0, 0, 0],
[0, 4, 0],
[0, 0, 8]]
Doubtful Dragonfly
x = [0, 4, 8]
print(np.diag(x))
# Output:
[[0, 0, 0],
[0, 4, 0],
[0, 0, 8]]
>>> np.diag(np.diag(x))
array([[0, 0, 0],
[0, 4, 0],
[0, 0, 8]])