[julia-users] Re: Please help me understand comprehensions for creating an array

2015-10-26 Thread Simon Danisch
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:

[julia-users] Re: Please help me understand comprehensions for creating an array

2015-10-26 Thread Kristoffer Carlsson
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). >

[julia-users] Re: Please help me understand comprehensions for creating an array

2015-10-26 Thread DNF
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 >

[julia-users] Re: Please help me understand comprehensions for creating an array

2015-10-26 Thread Ferran Mazzanti
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]

[julia-users] Re: Please help me understand comprehensions for creating an array

2015-10-26 Thread DNF
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)

[julia-users] Re: Please help me understand comprehensions for creating an array

2015-10-26 Thread DNF
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