具有numpy和scipy的矩阵的对角矩阵 [英] diagonal matrix of a matrix with numpy and scipy
本文介绍了具有numpy和scipy的矩阵的对角矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个矩阵(n * 1),我想用它做一个对角矩阵. 但是我不能用numpy构造它. 我尝试了numpy中的每个方法,例如此
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]]
这篇关于具有numpy和scipy的矩阵的对角矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文