scipy.ndimage.
mean#
- 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]