So basically I wrote this code:
a = [[], [], []] # a is an array of array
#### there is some code that modified a, then I want to clear array a ####
fill!(a, []) # set every element of a back to an empty array
push!(a[1], 1) # modify one of the element
println(a)
And then, the output becomes:
[[1], [1], [1]]
This means the code fill!(a, []) actually fills the same array reference to every index in a.
Is this a bug in Julia? If this method doesn't work, what alternative solution do I have?
[]is the same asAny[], which creates aVector{Any}. This means your code will be slow. If you know the element type of the inner vectors, specify them. E.g.[Int[] for _ in 1:3].