Numpy modify ndarray diagonal

后端 未结 4 2020
轻奢々
轻奢々 2020-12-06 05:11

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

4条回答
  •  鱼传尺愫
    2020-12-06 05:59

    If X is your array and c is the factor,

    X[np.diag_indices_from(X)] /= c
    

    See diag_indices_from in the Numpy manual.

提交回复
热议问题