当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Python SciPy ndimage.histogram用法及代码示例

本文简要介绍 python 语言中 scipy.ndimage.histogram 的用法。

用法:

scipy.ndimage.histogram(input, min, max, bins, labels=None, index=None)#

计算数组值的直方图,可选择在标签处。

直方图计算数组中值在由 min、max 和 bin 确定的 bin 内的频率。标签和索引关键字可以将直方图的范围限制在数组中指定的sub-regions。

参数

input array_like

为其计算直方图的数据。

min, max int

直方图 bin 范围的最小值和最大值。

bins int

箱子的数量。

labels 数组,可选

输入对象的标签。如果不是无,则必须与输入的形状相同。

index int 或整数序列,可选

要计算直方图的标签。如果为 None,则使用 label 大于零的所有值

返回

hist ndarray

直方图计数。

例子

>>> 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])

相关用法


注:本文由纯净天空筛选整理自scipy.org大神的英文原创作品 scipy.ndimage.histogram。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。