我有一个矩阵 (n*1),我想用它制作一个对角矩阵。 但我不能用 numpy 构造它。 我尝试了 numpy 中的每个方法,例如 this 中的方法
最佳答案
import numpy
arr = numpy.array([1,2,3])
mat = numpy.diag(arr)
print(mat)
>>>
[[1 0 0]
[0 2 0]
[0 0 3]]
关于python - 具有 numpy 和 scipy 的矩阵的对角矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19178061/