gpt4 book ai didi

python - 重新启动的 Cumsum

转载 作者:行者123 更新时间:2023-12-04 01:23:02 26 4
gpt4 key购买 nike

<分区>

我想在每次超过阈值 10000 时对数据进行分箱。

我已经尝试过了,但没有成功:

# data which is an array of floats

diff = np.diff(np.cumsum(data)//10000, prepend=0)

indices = (np.argwhere(diff > 0)).flatten()

问题是所有的箱子都不包含 10000,这是我的目标。


预期输出

input_data = [4000, 5000, 6000, 2000, 8000, 3000]
# (4000+5000+6000 >= 10000. Index 2)
# (2000+8000 >= 10000. Index 4)
Output: [2, 4]

我想知道是否有替代 for 循环的方法?

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