有人知道如何将数组{Float64,1} 转换为 Float64?
当我做:
M=rand(5,5)
a=M[:,1]' * M[:,1]
if a<0
print("Less than 0")
else
print("more")
end
我有一个错误:“isless 没有方法匹配 isless(::Array{Float64,2},::Int 32) in < at operators.jl:32
谁能告诉我如何转换
array{Float64,1}
一个到一个 float64
或者告诉我如何将 1 元素数组 a 与浮点数进行比较?谢谢
最佳答案
只有当您确定您的 Array{Float64, 1}
时,此操作才有意义。有一个元素。在这种情况下,您可以通过 a[1]
访问它.
对于您的示例,我建议使用 dot
函数 ( a = dot(M[:,1], M[:, 1])
) 或 norm
函数 ( a = norm(M[:, 1])^2
)
关于arrays - 如何将 Array{Float64, 1} 转换为 float 在 Julia 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30269194/