If you want constant values you should do
p = zeros(Nb) + a/Nb
or
p = ones(Nb) * a/Nb
On Monday, October 26, 2015 at 11:35:06 AM UTC+1, Ferran Mazzanti wrote:
>
> Hi folks,
>
> I try to create an array of constant float64 values. Something I did was:
>
> a = 0.8;
> Nb = 100;
> p = zeros(Nb)
> for i in 1:Nb
> p[i] = a/Nb
> end
>
> and typeof(p) returns
> Array{Float64,1}
> so far, so good :)
>
> But now I do the following instead to shorten things:
>
> a = 0.8;
> Nb = 100;
> p = [ a/Nb for i in 1:Nb]
>
> and typeof(p) returns
> Array{Any,1}
>
> which is *big* pain since I obviously wanted to create an array of floats.
> So the questions are:
> a) Is this behaviour normal/ expected?
> b) If so, why is it? What is the logic of that? Isn't it true that the
> normal behaviour, in the statistical sense of what *most* people would
> expect, is to
> get floats right away? Or am I missing something?
>
> I know I can always write
> p = float64( [ a/Nb for i in 1:Nb ] )
> but anyway...
>
> Cheers,
>
> Ferran.
>
>
> Array{Float64,1}
>
>
>