gpt4 book ai didi

python - 计算特定 bin 中的元素数

转载 作者:行者123 更新时间:2023-12-05 09:13:42 25 4
gpt4 key购买 nike

我很好奇是否可以计算直方图中特定 bin 的元素数量,即 0-10 范围内的所有元素

你会怎么做?

例如plt.hist(数据, bins=[0, 10, 20, 30, 40, 50, 100])是否有可能计算数据集中进入 bin 0-10 的所有元素

最佳答案

Matplotlib 直方图返回每个 bin 的计数:

import matplotlib.pyplot as plt
import numpy as np

x = np.random.uniform(0, 100, 1000)

counts, edges, plot = plt.hist(x, bins=[0, 10, 20, 50, 100])
print(counts)
print(counts[0]) # first bin

关于python - 计算特定 bin 中的元素数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55482071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com