I have a vector with the following values: dv = array([0., 0., 1.]).
How do I diagonalize this vector into a 3D array with each element in the vector have its own diagonal:
array([[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]]])
So far i have tried:
import numpy as np
a = np.zeros((3,3,3))
di = np.diag_indices(3,3)
a[di] = dv
This is almost correct, but it does not change all of the elements on the diagonal.
di. Does that give you any ideas?