scipy.ndimage.histogram¶
- scipy.ndimage.histogram(input, min, max, bins, labels=None, index=None)[源代码]¶
计算数组的值的直方图,也可以在标签处计算。
直方图计算数组中的值在由 min , max ,以及 bins 。这个 labels 和 index 关键字可以将直方图的范围限制在数组中的指定子区域。
- 参数
- inputarray_like
要计算直方图的数据。
- 最小、最大集成
直方图箱范围的最小值和最大值。
- bins集成
垃圾桶的数量。
- labelsARRAY_LIKE,可选
中对象的标签 input 。如果不是无,则必须与相同的形状 input 。
- index整型或整型序列,可选
要计算直方图的一个或多个标签。如果为None,则使用标签大于零的所有值
- 退货
- histndarray
直方图也算。
示例
>>> 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])