An ordinary way to make a tuple in Julia is like this:
n = 5
t2 = (n,n) # t2 = (5,5)
t3 = (n,n,n)# t3 = (5,5,5)
I want to make a tuple of arbitrary size functionally.
n = 5
someFunction(n,size) = ???
t10 = someFunction(n,10) # t10 = (5,5,5,5,5,5,5,5,5,5)
How can I realize this?
Any information would be appreciated.
Maybe what you are looking for is ntuple
?
julia> ntuple(_ -> 5, 10)
(5, 5, 5, 5, 5, 5, 5, 5, 5, 5)
Note that, you can also use tuple
or Tuple
:
julia> tuple((5 for _ in 1:10)...)
(5, 5, 5, 5, 5, 5, 5, 5, 5, 5)
julia> Tuple(5 for _ in 1:10)
(5, 5, 5, 5, 5, 5, 5, 5, 5, 5)
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