It's also perfectly normal/valid to do the loop explicitly. Just use Array(T, r, c) to allocate, or zeros(T, r, c) or fill(val,r,c) to allocate and initialize.
On Tue, Sep 15, 2015 at 2:38 PM, Stefan Karpinski <ste...@karpinski.org> wrote: > You can use array comprehensions, e.g.: > > julia> f(x,y) = 2x + 3y - 1 > f (generic function with 1 method) > > julia> [f(x,y) for x=1:7, y=1:5] > 7x5 Array{Int64,2}: > 4 7 10 13 16 > 6 9 12 15 18 > 8 11 14 17 20 > 10 13 16 19 22 > 12 15 18 21 24 > 14 17 20 23 26 > 16 19 22 25 28 > > > On Tue, Sep 15, 2015 at 3:53 AM, Michael Borregaard < > mkborrega...@gmail.com> wrote: > >> Hi, >> I am trying to migrate from R to julia. I am trying to wrap my head >> around: >> In R, there are the apply functions - when used with, e.g. a function >> that returns a 1d array of constant length, they will return a 2d array >> with the results. In julia, using map() will return a Array{Array{T, 1}, 1} >> . What is the best, ideomatic way of building an Array{T, 2} from repeated >> runs of a function? A hcat() call at the end of a forloop? Initializing an >> array with the right dimensions with zeros(T, r, c) an indexing inside a >> for loop? Or is there something smarter/nicer/better? >> >> Thanks, >> Michael >> > >