Having a 3D numpy array, where each 2D slice represents an individual matrix. I'm looking to replace the diagonal elements of every matrix with a specific set of values.
For instance, if I have a 3x3x3 array:
array([[[a1, a2, a3],
[a4, a5, a6],
[a7, a8, a9]],
[[b1, b2, b3],
[b4, b5, b6],
[b7, b8, b9]],
[[c1, c2, c3],
[c4, c5, c6],
[c7, c8, c9]]])
I'd like to replace the diagonals [a1, a5, a9], [b1, b5, b9], and [c1, c5, c9] with a new set of values for each matrix. How can I achieve this?
I would use integer indexing: