scipy.ndimage.variance¶
- scipy.ndimage.variance(input, labels=None, index=None)[源代码]¶
计算N-D图像阵列的值的方差,可选地在指定子区域。
- 参数
- inputarray_like
要处理的ND图像数据。
- labelsARRAY_LIKE,可选
标签定义子区域 input 。如果不是无,则必须与相同的形状 input 。
- index整型或整型序列,可选
labels 包括在输出中。如果为None(默认值),则为以下位置的所有值 labels 是非零的,则使用。
- 退货
- variance浮动或ndarray
方差值,对于每个子区域,如果 labels 和 index 都是指定的。
参见
示例
>>> a = np.array([[1, 2, 0, 0], ... [5, 3, 0, 4], ... [0, 0, 0, 7], ... [9, 3, 0, 0]]) >>> from scipy import ndimage >>> ndimage.variance(a) 7.609375
可使用指定要处理的要素 labels 和 index :
>>> lbl, nlbl = ndimage.label(a) >>> ndimage.variance(a, lbl, index=np.arange(1, nlbl+1)) array([ 2.1875, 2.25 , 9. ])
如果未给出索引,则所有非零值 labels 已处理:
>>> ndimage.variance(a, lbl) 6.1875