in a module, can I define a unspecified dimension array first, and then in a function give its particular dimensions?
Like
global const a=Array{Float64,2}()
But obviously the above give me an array.
However, the point is, just define a 2d array first, then I will initialize its dimensions in a function f, like,
function f(i::Int64,j::int64)
a=Array{Float64,2}(undef,i,j)
return nothing
end
Point is, in a module define a unspecified dimension 2d array a first, then in the function f give a particular dimensions, is it possible? If so how to do it?
I can think of the following
module Mod
global const a=Float64[]
function f(i::Int64,j::int64)
resize!(a,i*j)
reshape(a,(i,j))
return nothing
end
end
But is there better way?
You may ask why not just define the global array in the function f?
I can do this, but I would like to predefine it at the beginning of my module, so that I can see all the global variables at the beginning.
Also, I know we can do resize!, but resize! seems only works for 1D array.
Thanks in advance!