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
The np.fill_diagonal function is quite fast:
np.fill_diagonal
np.fill_diagonal(a, a.diagonal() / c)
where a is your array and c is your factor. On my machine, this method was as fast as @kwgoodman's a.flat[::n+1] /= c method, and in my opinion a bit clearer (but not as slick).
a
c
a.flat[::n+1] /= c