gpt4 book ai didi

python - 有没有办法在 python 中使用 binwidth = 0.1 的 bincount ?

转载 作者:太空宇宙 更新时间:2023-11-03 18:18:22 29 4
gpt4 key购买 nike

我有类似的东西[12.414261306701654、10.52589457006108、12.398125569114093、11.900971715356471、11.566273761189997、10.31504117886884、 10.235859974871904, 10.25704925592012, 10.296557787801154, 10.19010244226054]

假设我想要(10,10.1)(10.1,10.2),...中出现的次数

我认为 numpy.bincount 仅采用整数 bin 宽度,但是如果我将数组乘以 10 并使用 bincount,当我稍后绘制结果时 xscale 也偏离了 10,我不知道如何获得准确的绘图。

谢谢

最佳答案

看看np.histogram :

>>> import numpy as np
>>> data = [12.414261306701654, 10.52589457006108, 12.398125569114093, 11.900971715356471, 11.566273761189997, 10.31504117886884, 10.235859974871904, 10.25704925592012, 10.296557787801154, 10.19010244226054]
>>> counts, bin_edges = np.histogram(data, bins=np.arange(10, 12.6, 0.1))
>>> counts
array([0, 1, 3, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,
1, 1])

关于python - 有没有办法在 python 中使用 binwidth = 0.1 的 bincount ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24624866/

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