sorry for stupid simple question, newbie with Julia:
I would like to initialize array like this:
folds = [[], [], [], [], [], [], [], []], but not manually.
In Python I just write
folds = [[]] * 8, but this is not working with Julia.
How this is possible with Julia? I tried several times, but now success. Can you also explain to solution.
Thank you.
One way would be a list comprehension (although this of course isn't quite as concise as Python):
[[] for i=1:8]
The equivalent of folds = [[]] * 8 (which is probably not what you want!) in Julia is
folds = fill([], 8)
See the result of
push!(folds[1], 1)
8-element Array{Array{Any,1},1}:
Any[1]
Any[1]
Any[1]
Any[1]
Any[1]
Any[1]
Any[1]
Any[1]
and
folds[1].append(1)
# [[1], [1], [1], [1], [1], [1], [1], [1]]
On the other hand, a comprehension like [[] for i = 1:8] will create independent arrays in Julia and similar in python.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With