Julia: calling Array () with an array of dimensions

Suppose I want to create a multidimensional array whose dimensions / size is measured in the 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) 

It is unacceptable. In the above case, you should use:

 arr = Array(Float64, dims[1], dims[2], dims[3] ) 

I do not know the length of the dims ahead of time, so the above solution does not work for me. Is there a hurricane workaround beyond using some nasty sprintfs and eval?

Thanks!

+6
source share
1 answer

A really useful operator to remember in Julia is the "splat", ... In this case, you just want to:

 arr = Array(Float64, dims...) 
+10
source

All Articles