我是编程新手,我正在尝试创建一个随机数迭代器,它将接受 numpy 随机范围并计算 1-10 中每个数字出现的次数。
示例:随机范围从 1 到 5,它将计算 # 出现的次数。count1 出现一次,count2 出现 3 次,count 9 出现一次。
代码:
import numpy as np
x1 = np.random.random(10)
count1 = 0
count2 = 0
count3 = 0
count4 = 0
count5 = 0
count6 = 0
count7 = 0
count8 = 0
count9 = 0
count10 = 0
for x in range(1,x1):
if x == 1:
count1 += count1
elif x == 2:
count2 += count2
elif x == 3:
count3 += count3
elif x == 4:
count4 += count4
elif x == 5:
count5 += count5
elif x == 6:
count6 += count6
elif x == 7:
count7 += count7
elif x == 8:
count8 += count8
elif x == 9:
count9 += count9
elif x == 10:
count10 += count10
print(count1)
print(count2)
print(count3)
print(count4)
print(count5)
print(count6)
print(count7)
print(count8)
print(count9)
print(count10)
精慕HU
相关分类