julia> vec=[]
0-element Array{Any,1}
julia> for i in 1:10
global vec=vcat(vec,i)
end
julia> vec
10-element Array{Any,1}:
1
2
3
4
5
6
7
8
9
10
but how can I create row vector like this? - more precisely : initialize 1x0-dimensional (row) array
julia> vec=[nothing]
1-element Array{Nothing,1}:
nothing
julia> for i in 1:10
global vec=hcat(vec,i)
end
julia> vec
1×11 Array{Union{Nothing, Int64},2}:
nothing 1 2 3 4 5 6 7 8 9 10
This doesn’t work ↓
vec=reshape(vec,(0,1))
or this → reshape([],0,2)
julia> vec=[]
0-element Array{Any,1}
julia> vec=reshape(vec,(0,1))
0×1 Array{Any,2}
julia> for i in 1:10
global vec=hcat(vec,i)
end
ERROR: DimensionMismatch("mismatch in dimension 1 (expected 0 got 1)")
julia> x = Array{Int,2}(undef, 0,1)
0×1 Array{Int64,2}
julia> for i in 1:10
global x = vcat(x,i)
end
julia> x
10×1 Array{Int64,2}:
1
2
3
4
5
6
7
8
9
10
I must admit, I am still very very uncomfortable with
0×1 Array{Int64,2}
Okay 1xN Vector (Matrix) but with no elements… like
vec=[]
So there is such thing.
Because you can’t do this :
julia> vec=[]
0-element Array{Any,1}
julia> for i in 1:10
global vec=hcat(vec,i)
end
ERROR: DimensionMismatch("mismatch in dimension 1 (expected 0 got 1)")
Stacktrace:
[1] hcat(::Array{Any,1}, ::Int64) at ./abstractarray.jl:1421
[2] top-level scope at ./REPL[211]:2