I need to create a matrix with values from a numpy array. The values should be distributed over the matrix lines according to an array of indices.
Like this:
>>> values
array([ 0.73620381, 0.61843002, 0.33604769, 0.72344274, 0.48943796])
>>> inds
array([0, 1, 2, 3, 2])
>>> m = np.zeros((4, 5))
>>> for i, (index, value) in enumerate(zip(inds, values)):
m[index, i] = value
>>> m
array([[ 0.73620381, 0. , 0. , 0. , 0. ],
[ 0. , 0.61843002, 0. , 0. , 0. ],
[ 0. , 0. , 0.33604769, 0. , 0.48943796],
[ 0. , 0. , 0. , 0.72344274, 0. ]])
I'd like to know if there is a vectorized way to do it, i.e., without a loop. Any suggestions?