python - 获取关于从固定起点 (0,0) 的最大距离分布的信息
问题描述
我创建了一个模拟随机游走的程序,并将最大距离存储在一个列表中。步数是随机生成的。我正在尝试生成有关距固定起点的最大距离分布的数据(中值、均值、方差等)。但是,我相信我这样做是非常错误的。
代码:
walk_seed = 2025678
num_steps = 500 + 10 * (walk_seed % 11) - 50
np.random.seed(walk_seed)
journeys = 20000
max_distance = np.zeros(journeys)
for j in range(journeys):
x_c = 0
y_c = 0
max_x = 9
max_y = 6
current_max_distance = math.sqrt(max_x**2+max_y**2)
for i in range(num_steps):
direction = np.random.randint(0,3)
if direction == 0:
x_c += 1
if direction == 1:
x_c -= 1
if direction == 2:
y_c += 1
if direction == 3:
y_c -= 1
current_distance = math.sqrt(x_c * x_c + y_c * y_c)
current_distance_round = math.trunc(current_distance)
# print(current_distance_round)
if current_distance_round > current_max_distance:
current_max_distance = current_distance_round
max_distance[j] = current_distance_round
总共有 20000 次步行,所有步行都有固定的步数和最大距离。目前,如果当前距离大于最大距离,它将存储在列表中。但是,最大距离似乎无关紧要,因为我得到的数字太大(平均值 = 160,方差 = 107)。
解决方案
推荐阅读
- c - 在 C 中的多个文件中定义外部变量
- javascript - createjs 删除了画布上的所有现有信息?
- raspberry-pi - SparkFun RP2040 和 MicroPython
- arrays - Julia:一种从数组数组中获取矩阵的快速而优雅的方法
- python - skip-gram 模型的输出会是什么样子?
- swift - 在 Objc 文件中导入 SPM 包
- react-native - React Native(Expo)导航配置无法正确解析到正确的路线
- object - 错误代码:-2147024809 (80070057)“找不到特定对象”
- ssl - 下载文件时 SSL3 解密失败,但只能通过以太网而不是同一路由器的 Wi-Fi
- git - Gitlab工件在分支之间传递