【发布时间】:2016-05-23 02:17:13
【问题描述】:
考虑一个返回百分比的 numpy 数组的直方图计算:
# 500 random numbers between 0 and 10,000
values = np.random.uniform(0,10000,500)
# Histogram using e.g. 200 buckets
perc, edges = np.histogram(values, bins=200,
weights=np.zeros_like(values) + 100/values.size)
上面返回两个数组:
-
perc包含每对连续edges[ix]和edges[ix+1]中的值的%(即百分比)。 -
edges长度为len(hist)+1
现在,假设我要过滤 perc 和 edges,以便最终得到包含在新范围 [m, M] 内的 值 的百分比和边缘。 '
也就是说,我想使用perc 和edges 的子数组 对应于[m, M] 内的值区间。不用说,新的百分比数组仍然是指输入数组的总分数。我们只想过滤 perc 和 edges 以得到正确的子数组。
如何对perc 和edges 进行后处理?
m 和M 的值当然可以是任意数量。在上面的例子中,我们可以假设例如m = 0 和 M = 200。
【问题讨论】:
标签: python python-3.x numpy matplotlib histogram