I am having troubles accessing the value from the given indices:
indices = array([[[1, 1],
[1, 2],
[1, 3],
[2, 1],
[2, 2],
[2, 3],
[3, 1],
[3, 2],
[3, 3]],
[[1, 2],
[1, 3],
[1, 4],
[2, 2],
[2, 3],
[2, 4],
[3, 2],
[3, 3],
[3, 4]],
[[2, 1],
[2, 2],
[2, 3],
[3, 1],
[3, 2],
[3, 3],
[4, 1],
[4, 2],
[4, 3]],
[[2, 2],
[2, 3],
[2, 4],
[3, 2],
[3, 3],
[3, 4],
[4, 2],
[4, 3],
[4, 4]]])
for an array:
padded_x = array([[0, 0, 0, 0],
[0, 1, 1, 0],
[0, 1, 1, 0],
[0, 0, 0, 0]])
I tried accessing using result = padded_x[indices] but it returns result in shape (4, 9, 2, 4), I need it in shape (4,9). I do not want to use for loops as I am dealing very large arrays.
Context: The indices represent 3x3 neighbourhood indices at point [i,j]. To prevent the out of bounds array access, the original array has been padded (hence the name padded_x)
indices.indicesis (4,9,2), and you wantindices[:,:,0]to index the 1st dimension, andindices[:,:,1]for the second?