标题中的问题:我想创建一个长元组,其中填充了 1
.
mytuple = fill(1, (2018,))
但 Julia 返回一个数组
1
.2018-element Array{Int64,1}:
1
1
...
1
如果结果是重复的,请提前抱歉。
最佳答案
fill
用于数组,使用 tuple(ones(Int,2018)...)
代替或 ntuple(x->1, 2018)
如果你想使用更复杂的 init 函数。顺便说一句,你也可以使用 ntuple(x->1, Val(10))
提高代码的类型稳定性。
关于tuples - 如何在 Julia 中填充元组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48741908/