代码之家  ›  专栏  ›  技术社区  ›  Rares Dima

Julia缺少数组构造函数?

  •  3
  • Rares Dima  · 技术社区  · 7 年前

    我刚安装了朱莉娅后,看了一段时间。解释器和一个基本的hello-world程序可以工作,但是。。。如果数组构造函数失败,则会出现问题。

    我正在尝试运行文档中的基本示例 A = Array{Float64, 2}(2, 2); 我明白了:

    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
    

    底线问题:我想要一个普通的二维数组,出了什么问题以及如何修复?

    1 回复  |  直到 7 年前
        1
  •  5
  •   carstenbauer    7 年前

    从juliav0.7中获取未初始化数组的方法是 Array{Float64, 2}(undef, 2, 2) (注意 undef ).

    例如,要获得预初始化的数组,可以使用 fill(0., 2, 2) .

    (我猜您的问题是因为阅读了旧版本的文档。)

    推荐文章