The helpstring for fill, says:
help?> fill
search: fill fill! finally findall filter filter! filesize filemode FileSyntax FileSchema isfile CSVFile @__FILE__ CSVFileSyntax fieldtype fieldname
fill(x, dims)
Create an array filled with the value x. For example, fill(1.0, (5,5)) returns a 5×5 array of floats, with each element initialized to 1.0.
...
If x is an object reference, all elements will refer to the same object. fill(Foo(), dims) will return an array filled with the result of evaluating
Foo() once.
Note that last paragraph:
If
xis an object reference, all elements will refer to the same object.fill(Foo(), dims)will return an array filled with the result of evaluatingFoo()once.
So I was wondering, how does one construct an Array of n unique objects?
E.g. say I want an array of 3 empty, separate dictionaries.
Related: Creating an Array of Arrays in Julia
The best I can come up with is to use a comprehension:
julia> ds = [Dict() for _ in 1:3]
2-element Array{Dict{Any,Any},1}:
Dict()
Dict()
Dict()
Is this the best approach? Thanks!
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