我有一个矩阵嵌套向量的数据格式,例如:Array{Array{Float64,1},3},因为有需要这样存放数据的需求
然后我需要将给它重置大小为Array{Array{Float64,1},1} , 我使用reshape(x,:),在测试中没遇到问题,但是在整体项目代码中跑就提示convert转化异常!翻看源码也没理解为何会这样!
如果在跑的时候把数据放在全局变量里,再跑jupyter里跑reshape又没问题,不知道怎么回事,求大佬告知原因!
# 项目跑的代码
function flatten(x::Array{Array{T,1},3};row::Bool=false) where T <: Real
(row == true) && (x = permutedims(x,reverse(collect(1:ndims(x)),1,2)))
@show typeof(x),size(x)
global what = x
return reshape(x,:)
end
# 测试,这个跑的时候没异常
function fill_copy!(a::Array, x)
for i in eachindex(a)
@inbounds a[i] = copy(x)
end
return a
end
fill_copy(v, dims::NTuple{N, Integer}) where {N} = fill_copy!(Array{typeof(v),N}(undef, dims), v)
s = fill_copy(rand(Float64,3*3*3),(3,3,3))
@show typeof(s)
s1=reshape(s,:)
@show typeof(s1)