How to convert a column or row matrix to a diagonal matrix in Python?
For getting your desired output ,you can try python diagonal matrix method like this: import numpy as np a = np.array([1,2,3,4]) d = np.diag(a) # or simpler: d = np.diag([1,2,3,4]) print(d) Results in: [[1 0 0 0] [0 2 0 0] [0 0 3 0] [0 0 0 4]] If you have a row vector, you can do this: a = np.array([[1, 2, 3, 4]]) d =…
Answered Apr 14, 2021 · 1.1K Views Read answer →