浮点数组 JuliaLang 的标准差

C. *_*der 2 floating-point standard-deviation julia

我正在尝试运行 std(list),其中 list 是一个 Float 数组,但我收到下一个错误:

“MethodError:Array{Float64,1} 类型的对象不可调用使用方括号 [] 来索引数组。”

当使用[]时:

“参数错误:无效索引:0.4”

这是我的数组的第一个值。

我猜测“std()”在使用浮点参数时无效,无论如何要使其工作?

(现在我使用的是juliabox 0.6.2)

Jul*_*ner 6

这在 JuliaBox 0.6.2 中对我有用:

\n\n
VERSION\nv"0.6.2"\n\nA = [1 2 3 4 5]\n1\xc3\x975 Array{Int64,2}:\n 1  2  3  4  5\n\ns = std(A)\n1.5811388300841898\n
Run Code Online (Sandbox Code Playgroud)\n\n

正如 Hckr 在评论中指出的那样,您可能已经阴影std这样的内容:

\n\n
std = [1 2 3 4 5]\n1\xc3\x975 Array{Int64,2}:\n 1  2  3  4  5\n\nstd(std)\nMethodError: objects of type Array{Int64,2} are not callable\nUse square brackets [] for indexing an Array.\n
Run Code Online (Sandbox Code Playgroud)\n\n

正如 Bogumi\xc5\x82 Kami\xc5\x84ski 在评论中指出的那样,在 Julia 1.0.0 中,您需要执行using Statistics以下操作才能访问std函数:

\n\n
VERSION\nv"1.0.0"\n\nA = [1 2 3 4 5]\n1\xc3\x975 Array{Int64,2}:\n 1  2  3  4  5\n\n# Error here because using Statistics is needed in 1.0.0.\nstd(A)\nUndefVarError: std not defined\nStacktrace:\n [1] top-level scope at In[2]:1\n\nusing Statistics\nstd(A)\n1.5811388300841898\n
Run Code Online (Sandbox Code Playgroud)\n