numpy修改ndarray对角线 [英] Numpy modify ndarray diagonal
本文介绍了numpy修改ndarray对角线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在numpy中有什么方法可以获取对角线数组的引用? 我希望将阵列对角线除以某个因子 谢谢
is there any way in numpy to get a reference to the array diagonal? I want my array diagonal to be divided by a certain factor Thanks
推荐答案
如果X
是您的数组,而c
是因子,
If X
is your array and c
is the factor,
X[np.diag_indices_from(X)] /= c
请参见 diag_indices_from
在Numpy手册中.
See diag_indices_from
in the Numpy manual.
这篇关于numpy修改ndarray对角线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文