scipy.ndimage.
histogram#
- scipy.ndimage.histogram(input, min, max, bins, labels=None, index=None)[原始碼]#
計算陣列數值的直方圖,可選地針對標籤。
直方圖計算在由 min、max 和 bins 決定的區間內,陣列中數值的頻率。labels 和 index 關鍵字可以將直方圖的範圍限制在陣列中指定的子區域內。
- 參數:
- inputarray_like
用於計算直方圖的資料。
- min, maxint
直方圖區間範圍的最小值和最大值。
- binsint
區間數量。
- labelsarray_like,可選
input 中物件的標籤。如果不是 None,則必須與 input 具有相同的形狀。
- indexint 或 int 序列,可選
用於計算直方圖的標籤或標籤。如果為 None,則使用標籤大於零的所有值
- 返回:
- histndarray
直方圖計數。
範例
>>> import numpy as np >>> a = np.array([[ 0. , 0.2146, 0.5962, 0. ], ... [ 0. , 0.7778, 0. , 0. ], ... [ 0. , 0. , 0. , 0. ], ... [ 0. , 0. , 0.7181, 0.2787], ... [ 0. , 0. , 0.6573, 0.3094]]) >>> from scipy import ndimage >>> ndimage.histogram(a, 0, 1, 10) array([13, 0, 2, 1, 0, 1, 1, 2, 0, 0])
使用標籤且不使用索引,則會計算非零元素
>>> lbl, nlbl = ndimage.label(a) >>> ndimage.histogram(a, 0, 1, 10, lbl) array([0, 0, 2, 1, 0, 1, 1, 2, 0, 0])
索引可用於僅計算特定物件
>>> ndimage.histogram(a, 0, 1, 10, lbl, 2) array([0, 0, 1, 1, 0, 0, 1, 1, 0, 0])