Thanks - will take look.
On Monday, 21 September 2015 10:40:45 UTC+1, Mauro wrote: > > > Thanks all! I can now see what I was attempting makes no sense with the > > array comprehension and why I needed a nested solution. > > If you end up using it like so: > > vcat([[zeros(Int, k) for n = 1:binomial(J, k)] for k = 1:K]...) > > then have a look at https://github.com/mbauman/RaggedArrays.jl > > > On 21 Sep 2015 10:20, "Michael Hatherly" <[email protected] > <javascript:>> wrote: > > > >> The indices need to all be independent since otherwise you’d end up > >> producing an array with some rows/columns being of different length, > which > >> isn’t supported by Julia’s Array{T, N}. That’s fine for a loop since > for > >> i = 1:3, j = 1:i isn’t trying to fill up an array directly though. > >> > >> — Mike > >> > >> > >> On Monday, 21 September 2015 10:59:31 UTC+2, Alan Crawford wrote: > >>> > >>> Thanks Mike - precisely what i was after. > >>> > >>> While this is a perfectly acceptable solution I wondered > >>> whether, following Mauro's suggestion, it was worth opening an issue > in any > >>> case because it seems like it be nice to be able to link indexes in > array > >>> comprehensions in a similar way to for-loops. Views? > >>> > >>> > >>> On Monday, 21 September 2015 09:49:57 UTC+1, Michael Hatherly wrote: > >>>> > >>>> MyArray = [[zeros(Int, k) for n = 1:binomial(J, k)] for k = 1:K] > >>>> > >>>> seems to do what you want I think. Using 2 nested 1-d comprehensions > >>>> instead of a single 2-d comprehension. > >>>> > >>>> — Mike > >>>> > >>>> On Monday, 21 September 2015 10:37:06 UTC+2, Alan Crawford 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 k to define the number of element > >>>>>>>>> indexed by n. > >>>>>>>>> > >>>>>>>>> I was wondering if anyone knew how to create the desired array? > >>>>>>>>> > >>>>>>>>> Thanks > >>>>>>>>> Alan > >>>>>>>>> > >>>>>>>> > >>>>>>>> > >>>>>>> > >>>>>> > >>>>> > >
