简体   繁体   English

如何将Array {Float64,1}转换为浮动在朱莉娅?

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

Someone knows how to convert an array{Float64,1} to a Float64? 有人知道如何将数组{Float64,1}转换为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 我有一个错误:“isless在<at operators.jl:32中没有匹配isless(:: Array {Float64,2},:: Int 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? 有谁能告诉我如何将array{Float64,1}转换为float64或告诉我如何将1元素数组a与浮点数进行比较?

Thank you 谢谢

This operation really only makes sense when you are certain that your Array{Float64, 1} has a single element. 当您确定Array{Float64, 1}具有单个元素时,此操作才有意义。 In this case you can access it as a[1] . 在这种情况下,您可以将其作为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 ) 对于你的例子,我建议使用dot函数( a = dot(M[:,1], M[:, 1]) )或norm函数( a = norm(M[:, 1])^2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM