scipy.ndimage.
均值#
- scipy.ndimage.mean(input, labels=None, index=None)[源代码]#
计算数组在给定标签处的平均值。
- 参数:
- inputarray_like
用于计算不同区域元素平均值的数组。
- labelsarray_like, 可选
与 input 形状相同或可广播到相同形状的标签数组。所有共享相同标签的元素形成一个区域,将计算该区域内元素的平均值。
- indexint 或 int 序列, 可选
要计算平均值的对象的标签。默认为 None,在这种情况下,将计算标签大于 0 的所有值的平均值。
- 返回:
- outlist
与 index 长度相同的序列,包含 index 中标签所标识的不同区域的平均值。
示例
>>> from scipy import ndimage >>> import numpy as np >>> 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]