Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Array{Float64, 1} to float in julia?

Tags:

arrays

julia

Someone knows how to convert an array{Float64,1} to a Float64?

When I do:

M=rand(5,5)
a=M[:,1]' * M[:,1]
if a<0
    print("Less than 0")
else
    print("more")
end

I have an error: " isless has no method matching isless(::Array{Float64,2}, ::Int 32) in < at operators.jl:32

Can anyone tell me please how to convert the array{Float64,1} a to a float64 or tell me how to compare a 1 element array a to a float?

Thank you

like image 643
user4905479 Avatar asked May 15 '15 21:05

user4905479


1 Answers

This operation really only makes sense when you are certain that your Array{Float64, 1} has a single element. In this case you can access it as a[1].

For your example I'd recommend using the dot function (a = dot(M[:,1], M[:, 1])) or the norm function (a = norm(M[:, 1])^2)

like image 154
spencerlyon2 Avatar answered Sep 27 '22 23:09

spencerlyon2