配列があり、2x2 の重複しないウィンドウをスキャンして最大値を取得することで、より小さな配列を生成したいと考えています。次に例を示します。
import numpy as np
np.random.seed(123)
np.set_printoptions(linewidth=1000,precision=3)
arr = np.random.uniform(-1,1,(4,4))
res = np.zeros((2,2))
for i in xrange(res.shape[0]):
for j in xrange(res.shape[1]):
ii = i*2
jj = j*2
res[i][j] = max(arr[ii][jj],arr[ii+1][jj],arr[ii][jj+1],arr[ii+1][jj+1])
print arr
print res
したがって、次のようなマトリックス:
[[ 0.393 -0.428 -0.546 0.103]
[ 0.439 -0.154 0.962 0.37 ]
[-0.038 -0.216 -0.314 0.458]
[-0.123 -0.881 -0.204 0.476]]
これになるはずです:
[[ 0.439 0.962]
[-0.038 0.476]]
どうすればこれをより効率的に行うことができますか?