In [107]:
import numpy as np
P = 9; T = 8; X = 7; Z = 17; D = 5
data = np.arange(P*T*Z*D).reshape(P,T,Z,D)
ind = np.random.randint(0, Z, size=(P,T,X))
In [108]:
result = data.reshape(-1, D)[ind.reshape(-1, X)+np.arange(P*T)[..., None], :].reshape(P,T,X,D)
print(result[0, 7])
In [114]:
data[6, 7][ind[6, 7]]
Out[114]:
In [111]:
result = data[np.arange(P, dtype=int)[:, None, None, None], np.arange(T, dtype=int)[None, :, None, None], ind[..., None], np.arange(D, dtype=int)[None, None, None, :]]
In [113]:
print(result[6, 7])
In [ ]: