This will change on master soon but for now, either do this in a function
– with function arguments or local variables it's not a problem – or
specify an element type.

On Monday, October 26, 2015, Ferran Mazzanti <[email protected]>
wrote:

> Interesting answers :)
>
> But the problem is not filling an array with constant values, but filling
> an array with a comprehension :)
> I can change the
>
> p = [ a/Nb for i in 1:Nb]
>
> line with some other thing and still get the same answer. For instance:
> a = 0.8;
> Nb = 100;
> p = [ i*1.0/Nb for i in 1:Nb]
> typeof(p)
>
> still produces Array{Any,1}
>
>
>
> 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}
>>
>>
>>

Reply via email to