pandas 用于随机生成器的 Python 熊猫种子
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44068913/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python pandas seed for random generator
提问by Mr T.
I have a small question re: np.random.seed(seed=x)
I have a df SEED = 1
column of seed numbers
I would like to generate random number after choosing a seed from my df SEED
For example in the first simulation I'll use seed no 100 of the df SEED
and in the next simulation, I want to use seed no 200 of the SEED
df.
I've been trying out things , but to no avail.
Any hints for me?
Cheers
我有一个小问题:np.random.seed(seed=x)
我有一个 dfSEED = 1
种子数列
我想在从我的 df 中选择一个种子后生成随机数SEED
例如,在第一次模拟中,我将使用 df 的 100 号种子SEED
,在下一次模拟中,我想用SEED
df的200号种子。
我一直在尝试一些东西,但无济于事。
对我有什么提示吗?
干杯
回答by jezrael
It seems you need loop by values of column SEED
and set np.random.seed(x)
:
看来您需要按列的值循环SEED
并设置np.random.seed(x)
:
df = pd.DataFrame({'SEED':[100,200,500]})
print (df)
SEED
0 100
1 200
2 500
for i, x in df['SEED'].items():
print (x)
np.random.seed(x)
#some random function
a = np.random.randint(10, size=5)
print (a)
100
[8 8 3 7 7]
200
[9 0 4 7 9]
500
[7 1 1 8 7]
If need generate random value from list:
如果需要从列表中生成随机值:
L = [100,200,500]
a = np.random.choice(L, size=1)[0]
np.random.seed(a)
print (a)
500