I have a 2d array, A, with shape (n x m), where each element of the array at position (i,j) holds a third value k. I want to increment a 3d array with dimensions nxmxl at position (k,i,j) based on the 2d array value and position.
So for example if
A = [[0,1],[3,3]] -> I would want B to be
[[[1,0],
[0,0]],
[0,1],
[0,0]],
[0,0],
[0,1]],
[0,0],
[0,2]]]
How do you do this in numpy efficiently?
Bhas shape (4,2,2).Avalues could be indices of the first dimension (4), but not either of the others. Your problem might be easier ifAwas 1d, andB2d. The mix of 2 and 3d probably isn't essential.B[A,:;]will work, producing a (2,2,2,2) array.