diagonal matrix of a matrix with numpy and scipy
Question:
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
Answers:
import numpy
arr = numpy.array([1,2,3])
mat = numpy.diag(arr)
print(mat)
>>>
[[1 0 0]
[0 2 0]
[0 0 3]]
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
import numpy
arr = numpy.array([1,2,3])
mat = numpy.diag(arr)
print(mat)
>>>
[[1 0 0]
[0 2 0]
[0 0 3]]