, , , , broadcasting linear-indexing. , 3D -
m,n = x.shape
K = int(np.floor(patch_size/2.0))
R = np.arange(-K,K+1)
out = np.take(x,R[:,None]*n + R + (indices[0]*n+indices[1])[:,None,None])
x of (8,10), , . . -
1] :
In [105]:
...: x = np.random.randint(0,99,(8,10))
...: indices = np.array([[4,2,3],[6,3,7]])
...:
3] :
In [106]: # Posted code in the question ...
In [107]: patches[0]
Out[107]:
array([[[92, 21, 84],
[10, 52, 36],
[ 5, 62, 61]]])
In [108]: patches[1]
Out[108]:
array([[[71, 76, 75],
[80, 32, 55],
[77, 62, 42]]])
In [109]: patches[2]
Out[109]:
array([[[16, 88, 31],
[21, 84, 51],
[52, 36, 3]]])
3] :
In [110]: # Posted code in the solution earlier ...
In [111]: out
Out[111]:
array([[[92, 21, 84],
[10, 52, 36],
[ 5, 62, 61]],
[[71, 76, 75],
[80, 32, 55],
[77, 62, 42]],
[[16, 88, 31],
[21, 84, 51],
[52, 36, 3]]])