python - 经验洗牌检查python
问题描述
经验洗牌检查。运行计算实验以检查我们的改组代码是否像宣传的那样工作。编写一个程序,该程序采用整数命令行参数 m 和 n,对大小为 m 的数组进行 n 次洗牌,在每次洗牌之前用 a[i] = i 初始化,并编写一个 m×m 表,使得第 i 行给出所有 j 的 i 在位置 j 结束的次数. 数组中的所有条目都应接近 n/m。
我正在尝试在 python 中洗牌一个数组。我的代码是这样的:
import random
import sys
m = int(sys.argv[1])
n = int(sys.argv[2])
a = [] # a[i] = i
res =[] # for resit the array as a
for i in range(m):
a.append(i) # a[i] = i
res = a.copy()
for i in range(n):
random.shuffle(a)
print(a)
# i can't understand how to print m-m table that i gives number of times of i wound up
# in position j for all j.
a = res.copy()
print(n/m)
解决方案
推荐阅读
- html - IE11 中带有 html 内容的 IFrame 取消了对网页的导航
- python-3.x - 在 PyCharm 中运行测试时出现 UnicodeDecodeError
- javascript - ng2FileUpload 库 - 添加多个 formData
- android - Unity 游戏请求未反映在清单中的权限
- python-3.x - 如何将 Pytest 的日志附加到 Allure 报告中
- python - 如何使用 Elasticsearch 从 Django 的前端编辑/删除数据?
- python - 重新排列结果编号升序
- c# - 如何在 ReactiveUI 9.3.5 中全局处理异常?
- django - 需要在 Django 管理界面上显示用户计数其他数据计数
- xml - XML 语法检查 DTD 文件时发生错误