我有一个随机数的向量,我想使用randperm()函数随机置换,如下所示,但它不起作用.
X=rand(100000) # a vector of 100000 random elements
Y=randperm(X) # want to permute randomly the vector x
Run Code Online (Sandbox Code Playgroud)
返回的错误是: 错误:MethodError:没有方法匹配./boot.jl:237中的eval(:: Module,:: Any)中的randperm(:: Array {Float64,1})
谢谢
基于文档,randperm()接受一个整数n并给出长度为n的排列.您可以使用此顺序然后重新排序原始矢量:
julia> X = collect(1:5)
5-element Array{Int64,1}:
1
2
3
4
5
julia> Y = X[randperm(length(X))]
5-element Array{Int64,1}:
3
4
1
2
5
Run Code Online (Sandbox Code Playgroud)
您可以随时通过键入?function_nameREPL 来检查文档.
如果您的唯一目标是随机置换矢量,您还可以使用shuffle():
julia> shuffle(X)
5-element Array{Int64,1}:
5
4
1
2
3
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4379 次 |
| 最近记录: |