I have a vector length n
and a mxm
matrix. Usually m >> n
(m
is way bigger than n
). I need to repeatedly write the vector into the matrix, starting at the diagonal. For example:
vector v = [v_1, v_2, v_3]
with a 4x4
zero-matrix results in:
v_1, v_2, v_3, 0
0, v_1, v_2, v_3
0, 0, v_1, v_2
0, 0, 0, v_1
Since I have to do this quite often, it has to be reasonably fast. Right now I am looping over every row of the matrix in raw python and writing the vector into the required position, but this is slow.