I have known the errors:
x_shape = (x1, x2, x3, …)
index_shape = (i1, i2, i3, …)
dim
index[:,:,:,…] should < x_shape[dim]
here in my code max(index) = 3 = x_shape[dim=2], which is not satisfying the above rule.
so Invalid index happened.