Suppose I have the following arrays:
a = np.zeros([4,3])
b = np.asarray([0,1,2,1])
Now how can I set an element on each row in array a to 1 based on the column index indicated by array b? What I need is an array c which looks like below:
[[ 1. 0. 0.]
[ 0. 1. 0.]
[ 0. 0. 1.]
[ 0. 1. 0.]]
Alternatively, is there a way to directly convert array b to array c?