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

Asked By: Babak

||

Answers:

import numpy
arr = numpy.array([1,2,3])
mat = numpy.diag(arr)
print(mat)
>>> 
[[1 0 0]
 [0 2 0]
 [0 0 3]]
Answered By: Vincent
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.