Let's say I have a tensor:
q = np.arange(5*3*3).reshape(5,3,3)
I want to set the 3x3 diagonals to be 1, across axis 0 (i.e. where j=k).
I thought this should do it:
np.apply_along_axis(lambda x: np.fill_diagonal(x,1), 0, q)
but it doesn't seem to work.
What's the cleanest way to do this?