arrays - 在 Julia 中,如何创建唯一的空可变对象数组?

标签 arrays julia

helpstring for fill ,说:

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 evaluating Foo() once.

所以我想知道,如何构造一个由 n 个唯一对象组成的数组?

例如假设我想要一个由 3 个空的、独立的字典组成的数组。

<小时/>

相关:Creating an Array of Arrays in Julia

最佳答案

我能想到的最好的办法就是使用理解:

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/

相关文章:

javascript - 使用 Node JS 将 Uint8Array 转换为 Stream

arrays - 具有交替递增和递减值的最长子序列

http - 将 Julia `download` 的结果传递给内存而不是文件?

testing - 如何在 Julia 中创建动态命名的测试集?

arrays - 为任何整数数组定义函数

python - 二维 numpy 数组的条件数学运算检查一维并在不同维度上执行不同的操作

php - 使用 $_POST 从 HTML 中获取选择选项值

arrays - 从 Fortran 中的数组中删除索引值之后的所有行

range - 范围算术

performance - fun(n::Integer) 和 fun(n::T) 其中 T<:Integer 在性能/代码生成方面有区别吗?