[julia-users] Re: Array of vectors of variable number and lengths

2015-09-23 Thread Scott Jones
Do these really need to be arrays (or vectors)? If they are sparse, could you use a structure like Dict{Tuple,Any}? (you might want a SortedDict though). On Monday, September 21, 2015 at 4:08:13 AM UTC-4, Alan Crawford wrote: > > Hi, > > I'd like to be able to define an array of vectors where

[julia-users] Re: Array of vectors of variable number and lengths

2015-09-21 Thread Tomas Lycken
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

[julia-users] Re: Array of vectors of variable number and lengths

2015-09-21 Thread Alan Crawford
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,

Re: [julia-users] Re: Array of vectors of variable number and lengths

2015-09-21 Thread Alan Crawford
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 =

Re: [julia-users] Re: Array of vectors of variable number and lengths

2015-09-21 Thread Alan Crawford
Thanks all! I can now see what I was attempting makes no sense with the array comprehension and why I needed a nested solution. On 21 Sep 2015 10:20, "Michael Hatherly" wrote: > The indices need to all be independent since otherwise you’d end up > producing an array

Re: [julia-users] Re: Array of vectors of variable number and lengths

2015-09-21 Thread Mauro
> 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.

Re: [julia-users] Re: Array of vectors of variable number and lengths

2015-09-21 Thread Mauro
> 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 >

[julia-users] Re: Array of vectors of variable number and lengths

2015-09-21 Thread Alan Crawford
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

Re: [julia-users] Re: Array of vectors of variable number and lengths

2015-09-21 Thread Mauro
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) =>

[julia-users] Re: Array of vectors of variable number and lengths

2015-09-21 Thread Alan Crawford
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

[julia-users] Re: Array of vectors of variable number and lengths

2015-09-21 Thread Michael Hatherly
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 ​

[julia-users] Re: Array of vectors of variable number and lengths

2015-09-21 Thread Tomas Lycken
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

[julia-users] Re: Array of vectors of variable number and lengths

2015-09-21 Thread Michael Hatherly
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 =

[julia-users] Re: Array of vectors of variable number and lengths

2015-09-21 Thread Tomas Lycken
Now that we see the solution you were after, I note a few things: - What we *really* ended up with, is an Array{Array{Array{Int, 1}, 1}, 1}, which is something fundamentally different than an Array{Array{Int, 1}, 2}. - If we were to try to reshape this into a matrix-like shape,