打印多个随机排列
我正在尝试进行多个排列。从代码中:
# generate random Gaussian values
from numpy.random import seed
from numpy.random import randn
# seed random number generator
seed(1)
# generate some Gaussian values
values = randn(100)
print(values)
但是现在我想生成,例如,(值)20个排列。 使用代码:
import numpy as np
import random
from itertools import permutations
result = np.random.permutation(values)
print(result)
我只能观察到一个排列(或“手动”获得其他置换)。我希望我有很多排列(20或更多),因此自动计算每个置换量(来自值)的Durbin-Watson统计量。
from statsmodels.stats.stattools import durbin_watson
sm.stats.durbin_watson(np.random.permutation(values))
我该怎么办?
I am trying to do multiple permutations. From code:
# generate random Gaussian values
from numpy.random import seed
from numpy.random import randn
# seed random number generator
seed(1)
# generate some Gaussian values
values = randn(100)
print(values)
But now I would like to generate, for example, 20 permutations (of values).
With code:
import numpy as np
import random
from itertools import permutations
result = np.random.permutation(values)
print(result)
I can only observe one permutation (or "manually" get others). I wish I had many permutations (20 or more) and so automatically calculate the Durbin-Watson statistic for each permutation (from values).
from statsmodels.stats.stattools import durbin_watson
sm.stats.durbin_watson(np.random.permutation(values))
How can I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要从某些集合中获取20个排列,请Intial
itertools.permutations
iterator,然后使用next()
进行第一个20:当然,这些不会是随机的排列(即它们以有组织的方式计算,尝试
it.permutations(“ abcdef”)
,您会明白我的意思)。如果需要随机排列,则可以以相同的方式使用np.random.permunt.
:然后计算Durbin Watson统计信息:
To get 20 permutations out of some collection, intialize the
itertools.permutations
iterator and then usenext()
to take the first twenty:Of course, these won't be random permutations (i.e., they are calculated in an organized manner, try with
it.permutations("abcdef")
and you'll see what I mean). If you need random permutations, you can usenp.random.permutation
much in the same way:To then calculate the Durbin Watson statistic: