changing the values of the diagonal of a matrix in numpy

前端 未结 7 864
孤城傲影
孤城傲影 2020-12-08 19:20

how can I change the values of the diagonal of a matrix in numpy?

I checked Numpy modify ndarray diagonal, but the function there is not implemented in numpy v 1.3.0

相关标签:
7条回答
  • 2020-12-08 20:09

    You can do the following.

    Assuming your matrix is 4 * 4 matrix.

    indices_diagonal = np.diag_indices(4)
    
    yourarray[indices_diagonal] = Val
    
    0 讨论(0)
提交回复
热议问题