I think this is a limitation of list comprehensions: julia> [(i,j) for i=1:3, j=1:i] ERROR: i not defined in anonymous at no file
but doing the loop works: julia> for i=1:3, j=1:i @show i,j end (i,j) => (1,1) (i,j) => (2,1) (i,j) => (2,2) (i,j) => (3,1) (i,j) => (3,2) (i,j) => (3,3) Maybe you could check whether there is an issue about this already and if not file one? On Mon, 2015-09-21 at 10:37, Alan Crawford <a.r.crawf...@gmail.com> wrote: > Thanks Tomas. If I do: > > Y = [Array(Int64,n) for n in map(k -> binomial(J,k), 1:K)] > > Then Y[1] gives the desired result (i.e. Y[1][k] is a length 1 vector). > However, the issue for Y[2] and above. For example, if I do Y[2][k] where > k∈[1,binomial(J,2)] > then i get a length 1 vector, whereas I would like length 2 vector. Similarly > for Y[3][k] I would like a length 3 vector. > > > On Monday, 21 September 2015 09:23:56 UTC+1, Tomas Lycken wrote: > > > Ah. > > Maybe [Array(Int64,n) for n in map(k -> binomial(J,k), 1:K)] is what > you’re > looking for? > > // T > > On Monday, September 21, 2015 at 10:18:31 AM UTC+2, Alan Crawford wrote: > > The lower case k is intentional. I didn't want such a 'large' array as > the one created when I use K because large parts of that array would > be > redundant. Ideally, I want this array to be as small as possible, > especially since J and K might be quite a bit larger than in the > example. > > On Monday, 21 September 2015 09:13:53 UTC+1, Tomas Lycken wrote: > > > Are you sure that’s not just a typo between k and K (note the case > difference)? > > This works for me: > > J=10 > K=3 > MyArray = [Array(Int64,k) for k in 1:K, n in 1:binomial(J,K)] > > // T > > On Monday, September 21, 2015 at 10:08:13 AM UTC+2, Alan Crawford > wrote: > > Hi, > > I'd like to be able to define an array of vectors where the > number of vectors in the array is linked to the length of the > vector. For example, I want to be define an array with say 10 > scalars, 45 length 2 vectors, 120 length 3 vectors, .... and > so > on. Intuitively, I thought the following code might achieve > this: > > J=10 > K=3 > MyArray = [Array(Int64,k) for k in 1:K, n in 1:binomial(J,k)] > > > However, it seems i cannot use kto define the number of > element indexed by n. > > I was wondering if anyone knew how to create the desired > array? > > Thanks > Alan > > > >