python - python - 使用正常法则生成随机流量
问题描述
我正在寻找使用正常定律来生成伪随机事件。
我想要的是:
- 我给实体一个平均发生率和一个标准差值。每个实体将在很长一段时间内每个“平均”值时间生成一个事件。
- 每小时,我检查每个实体,并根据它们的平均值、标准偏差和正常定律,计算它们是否触发事件。
你会如何在 python 中做到这一点?我自己也不知道:(
谢谢
解决方案
reduce
在非空集上使用;偷基本and_
操作做你的路口。
from functools import reduce
from operator import and_
# Start with an empty set
a = set()
b = {1, 4, 8, 9}
c = {1, 5, 10, 15}
d = {1, 100, 200}
e = {1, 2, 3}
my_sets = [a, b, c, d, e]
print(reduce(and_, [q for q in my_sets if q]))
输出:
{1}
推荐阅读
- c - 创建空堆栈时出现 C 错误
- mysql - 使用 sql 生成组合
- babeljs - babel 没有使用 .babelrc。为什么?
- java - 队列只有最后一条消息
- c# - C# 使用多个文本框过滤 DataGridView?
- msbuild - msbuild Dotfuscator exec 任务给出错误 MSB3073 exited with code 1
- javascript - 无法在每个寄存器的注册警报消息中添加用于分配和打印唯一 ID 的代码
- ios - 未捕获的异常'InvalidPathValidation',原因:'(child:) 必须是非空字符串且不包含'.' '#' '$' '[' 或 ']''
- python - 如何应用函数来创建虚拟变量?
- javascript - 用于创建多个分组的普通 Javascript 循环 - 如何改进