Bug map works fine...
julia> g(x) = 1 / (1 + x)
g (generic function with 1 method)
julia> xs = [1.0, 2.0, 3.0, 4.0]
4-element Array{Float64,1}:
1.0
2.0
3.0
4.0
julia> gxs1 = map(g, xs)
4-element Array{Float64,1}:
0.5
0.333333
0.25
0.2
Evan Pu於 2014年11月4日星期二UTC+8上午7時01分37秒寫道:
>
> Consider the following interaction:
>
> julia> g(x) = 1 / (1 + x)
> g (generic function with 1 method)
>
> julia> typeof(g(1.0))
> Float64
>
> julia> xs = [1.0, 2.0, 3.0, 4.0]
> 4-element Array{Float64,1}:
> 1.0
> 2.0
> 3.0
> 4.0
>
> julia> gxs1 = [g(x) for x in xs]
> 4-element Array{Any,1}:
> 0.5
> 0.333333
> 0.25
> 0.2
>
> Why isn't gxs1 type of Array{Float64,1}?
> How could I force the type of gxs1 to be of an array of Float64?
>
> julia> gxs2 = [convert(Float64,g(x)) for x in xs]
> 4-element Array{Any,1}:
> 0.5
> 0.333333
> 0.25
> 0.2
>
> somehow this doesn't seem to work...
>
>
>
>