scipy.ndimage.mean¶
- scipy.ndimage.mean(input, labels=None, index=None)[源代码]¶
计算标签处数组的值的平均值。
- 参数
- inputarray_like
要在其上计算不同区域上的元素平均值的数组。
- labelsARRAY_LIKE,可选
形状相同的标签阵列,或与形状相同的可广播标签阵列 input 。共享相同标签的所有元素形成一个区域,在该区域上计算元素的平均值。
- index整型或整型序列,可选
要计算平均值的对象的标签。默认值为None,在这种情况下,将计算LABEL大于0的所有值的平均值。
- 退货
- out列表
长度与相同的序列 index 中的标签标注的不同区域的平均值 index 。
示例
>>> from scipy import ndimage >>> a = np.arange(25).reshape((5,5)) >>> labels = np.zeros_like(a) >>> labels[3:5,3:5] = 1 >>> index = np.unique(labels) >>> labels array([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 1, 1], [0, 0, 0, 1, 1]]) >>> index array([0, 1]) >>> ndimage.mean(a, labels=labels, index=index) [10.285714285714286, 21.0]