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.
请注意最后一段:
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 evaluatingFoo()
once.
所以我想知道,如何构造一个由 n
个唯一对象组成的数组?
例如假设我想要一个由 3 个空的、独立的字典组成的数组。
<小时/>最佳答案
我能想到的最好的办法就是使用理解:
julia> ds = [Dict() for _ in 1:3]
2-element Array{Dict{Any,Any},1}:
Dict()
Dict()
Dict()
这是最好的方法吗?谢谢!
关于arrays - 在 Julia 中,如何创建唯一的空可变对象数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58275540/