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
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
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,
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 =
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
> 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.
> 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
>
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
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) =>
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
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
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
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 =
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,
14 matches
Mail list logo