You can also rewrite it as p = Float64[ a/Nb for i in 1:Nb]
On Monday, October 26, 2015 at 12:08:33 PM UTC+1, Simon Danisch wrote: > > This is not wanted but expected behavior, since type inference of non > constant globals doesn't work very well (since the type can change > unpredictable). > Two fixes: put your code in a function, or declare a and Nb as const. > This is directly related: > http://docs.julialang.org/en/release-0.4/manual/performance-tips/ > > Best, > Simon > > Am Montag, 26. Oktober 2015 11:35:06 UTC+1 schrieb Ferran Mazzanti: >> >> 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} >> >> >>