Reputation: 4901
Suppose I want to create a multidimensional array whose dimensions / size per dimension are specified in an array. I want to do something like this:
dims = [2,5,6] # random example, the idea is I don't know dims ahead of time
arr = Array(Float64, dims)
That is not allowed. In the above case one should use:
arr = Array(Float64, dims[1], dims[2], dims[3] )
I don't know the length of dims ahead of time, so the above solution doesn't work for me. Is there a clean workaround outside of using some nasty sprintfs and eval?
Thanks!
Upvotes: 6
Views: 206
Reputation: 1406
A really useful operator to remember in Julia is the “splat”, ...
. In this case you simply want:
arr = Array(Float64, dims...)
Upvotes: 10