In numpy, I have a 2d array like:
[
[1 2 3 4 5]
[2 3 1 4 5]
.....
[3 5 2 3 5]
]
I want to replace each element in this array into a 1d array, e.g.
1 -> [0 0 0 0 1]
2 -> [0 0 0 1 0]
etc.
This will convert elements into arrays, and the whole 2d array into a 3d array.
I tried few things, but nothing worked. What should be the right way to do so?
Thanks.
Suppose this is your 2d array:
Create the array:
You can look upon this array as a mapping:
Then the array you desire is given by
y[x]