Julia中用随机数填充数组:类型转换错误

问题描述 投票:0回答:0

我想知道是否有人可以帮我解释这个错误信息。

运行块时

using Distributions
mu = [ 0; 0 ]
cov = [ 1 2 ; 2 4]
c = cov * cov / 10;
d = MvNormal(mu,c);
mc_reps = 10
p = 2
q = 1
r = p-q
x = rand(d,p)
errors = [Array{Float64,2} for _ in 1:mc_reps]
for i in 1:mc_reps
    errors[i] = rand(d,p)
end

我收到错误信息:

MethodError: Cannot `convert` an object of type Matrix{Float64} to an object of type DataType
Closest candidates are:
  convert(::Type{T}, ::T) where T at Base.jl:61

Stacktrace:
 [1] setindex!(A::Vector{DataType}, x::Matrix{Float64}, i1::Int64)
   @ Base ./array.jl:966
 [2] top-level scope
   @ ./In[34]:13

有人可以帮我解释这个错误信息吗?非常感谢!

arrays multidimensional-array julia
© www.soinside.com 2019 - 2024. All rights reserved.