【发布时间】:2018-08-10 02:27:23
【问题描述】:
我有一个大小为3*10 的 NumPy 数组,我想从每一行中提取不同大小的子行。子行以像素大小不同的中间像素为中心。然后我取每个子行的平均数。我在下面有一个伪示例:
import numpy as np
arr = np.arange(1,31).reshape((3,10))
pixel_size = np.array([2,3,1])
## the subrow centers in the middle of the array, index 5
mask = [[5-2:5+2],[5-3:5+3],[5-1:5+1]] ## index for each row
### submatrix = arr[;,mask]
submatrix = [[3,4,5,6],[12,13,14,15,16,17],[24,25]]
## output = np.mean(submatrix, axis=1) output is the average number of each row in the submatrix
output = [4.5,14.5,24.5]
如果我有超过 1000 万行,我该如何快速处理这种情况。
【问题讨论】:
-
这个问题有点看不懂。更清晰的询问方式是显示一些输入和预期输出。