How to fill a tuple in Julia?

Question as in title: I would like to create a long tuple filled with 1.

mytuple = fill(1, (2018,))

but Julia returns an array of 1.

2018-element Array{Int64,1}:
1
1
...
1

Sorry in advance if it turns out to be a duplicate.

Upvotes: 4

Views: 2904

Answers (1)

Gnimuc
Gnimuc

Reputation: 8566

fill is for arrays, use tuple(ones(Int,2018)...) instead or ntuple(x->1, 2018) if you wanna use a more complex init function. BTW, you might also use ntuple(x->1, Val(10)) to improve the type stability of the code.

Upvotes: 5

Related Questions