在Julia中是否可以将数组{Num,1}转换为数组{Float64,1}?

在Julia中是否可以将数组{Num,1}转换为数组{Float64,1}?,julia,typed-arrays,ijulia-notebook,Julia,Typed Arrays,Ijulia Notebook,我有下面的函数,它在Julia中使用了符号。在策划之前一切都很顺利 using Distributions using Plots using Symbolics using SymbolicUtils function BinomialMeasure(iter::Int64, p::Float64, current_level = nothing) @variables m0 m1 if current_level == nothing current_level = [1] e

我有下面的函数,它在Julia中使用了符号。在策划之前一切都很顺利

using Distributions
using Plots
using Symbolics
using SymbolicUtils

function BinomialMeasure(iter::Int64, p::Float64, current_level = nothing)

@variables m0 m1

if current_level == nothing
    current_level = [1]
end
next_level = []
for item in current_level
    append!(next_level, m0*item)
    append!(next_level, m1*item)
end

If iter != 0
    current_level = next_level
    return BinomialMeasure(iter - 1, p , current_level)
else
    return [substitute(i, Dict([m0 => p, m1 => 1 - p])) for i in next_level]
end
end

y = BinomialMeasure(10, 0.4)
x = [( i + 1 ) / length(y) for i = 1:length(y) ]
append!(x, 0)
append!(y,0)
plot(x,y) 
然后返回以下内容:

MethodError: no method matching AbstractFloat(::Num)
Closest candidates are:
AbstractFloat(::Real, !Matched::RoundingMode) where T<:AbstractFloat at rounding.jl:200
AbstractFloat(::T) where T<:Number at boot.jl:716
AbstractFloat(!Matched::Bool) at float.jl:258 
MethodError:没有与AbstractFloat(::Num)匹配的方法
最接近的候选人是:

AbstractFloat(::Real,!Matched::RoundingMode),其中T查看另一个答案

通过简单阅读论坛上关于符号的帖子,我的理解是,你并不是真的“应该”从符号中获得真正的价值。作为一个黑客的工作环境,你可以这样做

y_floats = [parse(Float64, string(i)) for i in y]

您可以访问字段
val
,而无需使用
string
parse

y_val = [i.val for i in y]

这当然比解析字符串有更好的性能,这应该是正确的答案。以防万一有人来这里发现是否有可能将某种类型的数组转换为另一种类型。像这样的东西通常是有效的:
convert.(Float64,A)
其中
A
是一个
Int64
Float32
的数组。注意单词
convert
后的广播点