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:
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).
>
I learn new great stuff all the time with this language:
You should actually do
p = fill(a/Nb, Nb)
On Monday, October 26, 2015 at 12:59:03 PM UTC+1, DNF wrote:
>
> If you want constant values you should do
>
> p = zeros(Nb) + a/Nb
> or
> p = ones(Nb) * a/Nb
>
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]
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)
OK. The phrasing of the question indicated to me that you were trying to
create an array of Float64 values, and that the comprehension was just the
tool to accomplish that.
In that case, Kristoffer Carlsson gave a good answer:
p = Float64[ a/Nb for i in 1:Nb]
On Monday, October 26, 2015 at