How to have multidimensional array with different length in Julia
up vote
1
down vote
favorite
I need to make a sequence of an array with different length by reading a dataset. I need to call each of them in a loop so probably I need some sort of indexing in order to call them. For example, how can I create the following sequence:
P[1]=[1 2 3 4]
P[2]=[1 4]
P[3]=[8 9 0 0 5 6]
.
.
.
arrays julia-lang
add a comment |
up vote
1
down vote
favorite
I need to make a sequence of an array with different length by reading a dataset. I need to call each of them in a loop so probably I need some sort of indexing in order to call them. For example, how can I create the following sequence:
P[1]=[1 2 3 4]
P[2]=[1 4]
P[3]=[8 9 0 0 5 6]
.
.
.
arrays julia-lang
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I need to make a sequence of an array with different length by reading a dataset. I need to call each of them in a loop so probably I need some sort of indexing in order to call them. For example, how can I create the following sequence:
P[1]=[1 2 3 4]
P[2]=[1 4]
P[3]=[8 9 0 0 5 6]
.
.
.
arrays julia-lang
I need to make a sequence of an array with different length by reading a dataset. I need to call each of them in a loop so probably I need some sort of indexing in order to call them. For example, how can I create the following sequence:
P[1]=[1 2 3 4]
P[2]=[1 4]
P[3]=[8 9 0 0 5 6]
.
.
.
arrays julia-lang
arrays julia-lang
edited Nov 10 at 22:03
marc_s
566k12610921245
566k12610921245
asked Nov 10 at 21:59
Reabo
114
114
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
Here it is:
julia> P = Vector{Vector{Int64}}([[1,2,3,4],[1,4],[8,9,0,0,5,6]])
3-element Array{Array{Int64,1},1}:
[1, 2, 3, 4]
[1, 4]
[8, 9, 0, 0, 5, 6]
julia> P[1]
4-element Array{Int64,1}:
1
2
3
4
julia> P[2]
2-element Array{Int64,1}:
1
4
julia> P[3]
6-element Array{Int64,1}:
8
9
0
0
5
6
If you want to add a new element use push!()
:
julia> push!(P,[7,8,9])
4-element Array{Array{Int64,1},1}:
[1, 2, 3, 4]
[1, 4]
[8, 9, 0, 0, 5, 6]
[7, 8, 9]
Thanks, but my problem is that this sequence is very long and I cannot do the first line of your code manually.
– Reabo
Nov 10 at 22:12
I found this and seems it works, thanks V=Vector{Vector{Float64}}(100)
– Reabo
Nov 10 at 22:18
no problem - I edited my answer. You can create an emptyArray
byP = Vector{Vector{Int64}}()
and then justpush!
to it.
– Przemyslaw Szufel
Nov 10 at 22:18
if you know theArray
sizeVector{Vector{Int64}}(undef, N)
and then usingP[n]=...
is of course better (note theundef
)
– Przemyslaw Szufel
Nov 10 at 22:21
1
Initialize empty:P = Vector{Int}
. If you already know the entries:P = [[1,2,3,4],[1,4],[8,9,0,0,5,6]]
. No need to specify the type in front of the literal.
– DNF
Nov 11 at 15:56
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Here it is:
julia> P = Vector{Vector{Int64}}([[1,2,3,4],[1,4],[8,9,0,0,5,6]])
3-element Array{Array{Int64,1},1}:
[1, 2, 3, 4]
[1, 4]
[8, 9, 0, 0, 5, 6]
julia> P[1]
4-element Array{Int64,1}:
1
2
3
4
julia> P[2]
2-element Array{Int64,1}:
1
4
julia> P[3]
6-element Array{Int64,1}:
8
9
0
0
5
6
If you want to add a new element use push!()
:
julia> push!(P,[7,8,9])
4-element Array{Array{Int64,1},1}:
[1, 2, 3, 4]
[1, 4]
[8, 9, 0, 0, 5, 6]
[7, 8, 9]
Thanks, but my problem is that this sequence is very long and I cannot do the first line of your code manually.
– Reabo
Nov 10 at 22:12
I found this and seems it works, thanks V=Vector{Vector{Float64}}(100)
– Reabo
Nov 10 at 22:18
no problem - I edited my answer. You can create an emptyArray
byP = Vector{Vector{Int64}}()
and then justpush!
to it.
– Przemyslaw Szufel
Nov 10 at 22:18
if you know theArray
sizeVector{Vector{Int64}}(undef, N)
and then usingP[n]=...
is of course better (note theundef
)
– Przemyslaw Szufel
Nov 10 at 22:21
1
Initialize empty:P = Vector{Int}
. If you already know the entries:P = [[1,2,3,4],[1,4],[8,9,0,0,5,6]]
. No need to specify the type in front of the literal.
– DNF
Nov 11 at 15:56
add a comment |
up vote
2
down vote
Here it is:
julia> P = Vector{Vector{Int64}}([[1,2,3,4],[1,4],[8,9,0,0,5,6]])
3-element Array{Array{Int64,1},1}:
[1, 2, 3, 4]
[1, 4]
[8, 9, 0, 0, 5, 6]
julia> P[1]
4-element Array{Int64,1}:
1
2
3
4
julia> P[2]
2-element Array{Int64,1}:
1
4
julia> P[3]
6-element Array{Int64,1}:
8
9
0
0
5
6
If you want to add a new element use push!()
:
julia> push!(P,[7,8,9])
4-element Array{Array{Int64,1},1}:
[1, 2, 3, 4]
[1, 4]
[8, 9, 0, 0, 5, 6]
[7, 8, 9]
Thanks, but my problem is that this sequence is very long and I cannot do the first line of your code manually.
– Reabo
Nov 10 at 22:12
I found this and seems it works, thanks V=Vector{Vector{Float64}}(100)
– Reabo
Nov 10 at 22:18
no problem - I edited my answer. You can create an emptyArray
byP = Vector{Vector{Int64}}()
and then justpush!
to it.
– Przemyslaw Szufel
Nov 10 at 22:18
if you know theArray
sizeVector{Vector{Int64}}(undef, N)
and then usingP[n]=...
is of course better (note theundef
)
– Przemyslaw Szufel
Nov 10 at 22:21
1
Initialize empty:P = Vector{Int}
. If you already know the entries:P = [[1,2,3,4],[1,4],[8,9,0,0,5,6]]
. No need to specify the type in front of the literal.
– DNF
Nov 11 at 15:56
add a comment |
up vote
2
down vote
up vote
2
down vote
Here it is:
julia> P = Vector{Vector{Int64}}([[1,2,3,4],[1,4],[8,9,0,0,5,6]])
3-element Array{Array{Int64,1},1}:
[1, 2, 3, 4]
[1, 4]
[8, 9, 0, 0, 5, 6]
julia> P[1]
4-element Array{Int64,1}:
1
2
3
4
julia> P[2]
2-element Array{Int64,1}:
1
4
julia> P[3]
6-element Array{Int64,1}:
8
9
0
0
5
6
If you want to add a new element use push!()
:
julia> push!(P,[7,8,9])
4-element Array{Array{Int64,1},1}:
[1, 2, 3, 4]
[1, 4]
[8, 9, 0, 0, 5, 6]
[7, 8, 9]
Here it is:
julia> P = Vector{Vector{Int64}}([[1,2,3,4],[1,4],[8,9,0,0,5,6]])
3-element Array{Array{Int64,1},1}:
[1, 2, 3, 4]
[1, 4]
[8, 9, 0, 0, 5, 6]
julia> P[1]
4-element Array{Int64,1}:
1
2
3
4
julia> P[2]
2-element Array{Int64,1}:
1
4
julia> P[3]
6-element Array{Int64,1}:
8
9
0
0
5
6
If you want to add a new element use push!()
:
julia> push!(P,[7,8,9])
4-element Array{Array{Int64,1},1}:
[1, 2, 3, 4]
[1, 4]
[8, 9, 0, 0, 5, 6]
[7, 8, 9]
edited Nov 10 at 22:18
answered Nov 10 at 22:09
Przemyslaw Szufel
1,239110
1,239110
Thanks, but my problem is that this sequence is very long and I cannot do the first line of your code manually.
– Reabo
Nov 10 at 22:12
I found this and seems it works, thanks V=Vector{Vector{Float64}}(100)
– Reabo
Nov 10 at 22:18
no problem - I edited my answer. You can create an emptyArray
byP = Vector{Vector{Int64}}()
and then justpush!
to it.
– Przemyslaw Szufel
Nov 10 at 22:18
if you know theArray
sizeVector{Vector{Int64}}(undef, N)
and then usingP[n]=...
is of course better (note theundef
)
– Przemyslaw Szufel
Nov 10 at 22:21
1
Initialize empty:P = Vector{Int}
. If you already know the entries:P = [[1,2,3,4],[1,4],[8,9,0,0,5,6]]
. No need to specify the type in front of the literal.
– DNF
Nov 11 at 15:56
add a comment |
Thanks, but my problem is that this sequence is very long and I cannot do the first line of your code manually.
– Reabo
Nov 10 at 22:12
I found this and seems it works, thanks V=Vector{Vector{Float64}}(100)
– Reabo
Nov 10 at 22:18
no problem - I edited my answer. You can create an emptyArray
byP = Vector{Vector{Int64}}()
and then justpush!
to it.
– Przemyslaw Szufel
Nov 10 at 22:18
if you know theArray
sizeVector{Vector{Int64}}(undef, N)
and then usingP[n]=...
is of course better (note theundef
)
– Przemyslaw Szufel
Nov 10 at 22:21
1
Initialize empty:P = Vector{Int}
. If you already know the entries:P = [[1,2,3,4],[1,4],[8,9,0,0,5,6]]
. No need to specify the type in front of the literal.
– DNF
Nov 11 at 15:56
Thanks, but my problem is that this sequence is very long and I cannot do the first line of your code manually.
– Reabo
Nov 10 at 22:12
Thanks, but my problem is that this sequence is very long and I cannot do the first line of your code manually.
– Reabo
Nov 10 at 22:12
I found this and seems it works, thanks V=Vector{Vector{Float64}}(100)
– Reabo
Nov 10 at 22:18
I found this and seems it works, thanks V=Vector{Vector{Float64}}(100)
– Reabo
Nov 10 at 22:18
no problem - I edited my answer. You can create an empty
Array
by P = Vector{Vector{Int64}}()
and then just push!
to it.– Przemyslaw Szufel
Nov 10 at 22:18
no problem - I edited my answer. You can create an empty
Array
by P = Vector{Vector{Int64}}()
and then just push!
to it.– Przemyslaw Szufel
Nov 10 at 22:18
if you know the
Array
size Vector{Vector{Int64}}(undef, N)
and then using P[n]=...
is of course better (note the undef
)– Przemyslaw Szufel
Nov 10 at 22:21
if you know the
Array
size Vector{Vector{Int64}}(undef, N)
and then using P[n]=...
is of course better (note the undef
)– Przemyslaw Szufel
Nov 10 at 22:21
1
1
Initialize empty:
P = Vector{Int}
. If you already know the entries: P = [[1,2,3,4],[1,4],[8,9,0,0,5,6]]
. No need to specify the type in front of the literal.– DNF
Nov 11 at 15:56
Initialize empty:
P = Vector{Int}
. If you already know the entries: P = [[1,2,3,4],[1,4],[8,9,0,0,5,6]]
. No need to specify the type in front of the literal.– DNF
Nov 11 at 15:56
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243831%2fhow-to-have-multidimensional-array-with-different-length-in-julia%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown