How to get a 2D np.array with value 1 at indices represented by values in 1D np.array in Python.
Example:
[1, 2, 5, 1, 2]
should be converted to
[[0, 1, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 1],
[0, 1, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0]]
Here you already know the width (shape[2]) value of the new array beforehand.
I can do it manually but is there any way to do it directly using NumPy methods for faster execution? The dimension of my array is quite large and I have to do this for all iteration. Thus, doing this manually for each iteration is quite computationally demanding.