Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia missing array constructors?

Tags:

arrays

julia

I have just installed julia after looking at it for a while. The interpreter and a basic hello world program works but... something is not going well if the array constructor.

I am trying to run the basic example from the documentation A = Array{Float64, 2}(2, 2); and I get this:

julia> A = Array{Float64, 2}(2, 2);
ERROR: MethodError: no method matching Array{Float64,2}(::Int64, ::Int64)
Closest candidates are:
  Array{Float64,2}(::UndefInitializer, ::Int64, ::Int64) where T at boot.jl:396
  Array{Float64,2}(::UndefInitializer, ::Int64...) where {T, N} at boot.jl:400
  Array{Float64,2}(::UndefInitializer, ::Integer, ::Integer) where T at sysimg.jl:143
  ...
Stacktrace:
 [1] top-level scope at none:0

I realize this is a dumb question and it might very well be against the spirit of SO but google had yielded no results and this is an example copy pasted from the documentation after all.

Bottom line question: I want a plain old 2d array, what goes wrong and how to fix?

like image 733
Rares Dima Avatar asked Jun 02 '26 20:06

Rares Dima


1 Answers

From Julia v0.7 on the way to get an uninitialized array is Array{Float64, 2}(undef, 2, 2) (note the undef).

To get a preinitialized array you could for example use fill(0., 2, 2).

(I guess your problem arose from reading an old version of the documentation.)

like image 58
carstenbauer Avatar answered Jun 05 '26 11:06

carstenbauer