Given an array
d = np.random.randn(100)
and an index array
i = np.random.random_integers(low=3, high=d.size - 5, size=20)
how can I efficiently create a 2d array r with
r.shape = (20, 8)
such that for all j=0..19,
r[j] = d[i[j]-3:i[j]+5]
In my case, the arrays are quite large (~200000 instead of 100 and 20), so something quick would be useful.
lowandhighmake any difference? Likelow=0, high=d.size - 8andd[i[j]:i[j]+8]?iis<3, theni[j]-3is negative. similar for the upper bound.all(0<=elem<=92 for elem in i) is Truethend[i[j]:i[j]+8]would be the same, right?