在numpy中更改矩阵的对角线的值 [英] changing the values of the diagonal of a matrix in numpy
本文介绍了在numpy中更改矩阵的对角线的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何更改numpy中矩阵对角线的值?
how can I change the values of the diagonal of a matrix in numpy?
我检查了 Numpy修改ndarray对角线,但是该函数未在numpy v中实现1.3.0.
I checked Numpy modify ndarray diagonal, but the function there is not implemented in numpy v 1.3.0.
让我们说我们有一个np.array X,我想将对角线的所有值都设置为0.
lets say we have a np.array X and I want to set all values of the diagonal to 0.
推荐答案
您尝试过numpy.fill_diagonal
吗?请参阅以下 answer 和此
Did you try numpy.fill_diagonal
? See the following answer and this discussion. Or the following from the documentation (although currently broken):
http://docs.scipy.org/doc/numpy/reference/generation/numpy.fill_diagonal.html
这篇关于在numpy中更改矩阵的对角线的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文