Diagonal Matrix Of A Matrix With Numpy And Scipy
I have a matrix (n*1) and I want to make a diagonal matrix with it. but I can't construct it with numpy. I tried each methods in numpy such as methods in this
Solution 1:
import numpy
arr = numpy.array([1,2,3])
mat = numpy.diag(arr)
print(mat)
>>>
[[1 0 0]
[0 2 0]
[0 0 3]]
Post a Comment for "Diagonal Matrix Of A Matrix With Numpy And Scipy"