Standard deviation for float array JuliaLang

I'm trying to run std(list), where list is a Float array but I receive the next error:

"MethodError: objects of type Array{Float64,1} are not callable Use square brackets [] for indexing an Array."

And when using []:

"ArgumentError: invalid index: 0.4"

Which is the first value of my array.

I'm guessing "std()" is not valid while using float arguments, anyway to make it work??

(Right now I'm using juliabox 0.6.2)

3

1 Answer

This worked for me in JuliaBox 0.6.2:

VERSION
v"0.6.2"
A = [1 2 3 4 5]
1×5 Array{Int64,2}: 1 2 3 4 5
s = std(A)
1.5811388300841898

As pointed out by Hckr in the comments, you may have shadowed std something like this:

std = [1 2 3 4 5]
1×5 Array{Int64,2}: 1 2 3 4 5
std(std)
MethodError: objects of type Array{Int64,2} are not callable
Use square brackets [] for indexing an Array.

As pointed out by Bogumił Kamiński in the comments, in Julia 1.0.0 you need to do using Statistics to access the std function:

VERSION
v"1.0.0"
A = [1 2 3 4 5]
1×5 Array{Int64,2}: 1 2 3 4 5
# Error here because using Statistics is needed in 1.0.0.
std(A)
UndefVarError: std not defined
Stacktrace: [1] top-level scope at In[2]:1
using Statistics
std(A)
1.5811388300841898

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like