m = []
initializes an empty array of dimension 1. I want to initialize an empty array of dimension 2 (to which I'll append values later on). Is this possible?
m = []
initializes an empty array of dimension 1. I want to initialize an empty array of dimension 2 (to which I'll append values later on). Is this possible?
It's now much simpler to create empty arrays:
Empty n-dimensional arrays can now be created using multiple semicolons inside square brackets.
julia> m = [;;]
# 0×0 Matrix{Any}
julia> m = [;;;]
# 0×0×0 Array{Any, 3}
Note that this is just syntactic sugar for constructing an uninitialized Array
:
julia/test/syntax.jl#L3143-L3146
@test [] == Array{Any}(undef, 0) @test [;] == Array{Any}(undef, 0) @test [;;] == Array{Any}(undef, 0, 0) @test [;;;] == Array{Any}(undef, 0, 0, 0)
As of Julia 1.0 you can use:
m = Array{Float64}(undef, 0, 0)
for an (0,0)-size 2-D Matrix storing Float64
values and more in general:
m = Array{T}(undef, a, b, ...,z)
for an (a,b,...,z)-size multidimensional Tensor (whose content is garbage of type T
).
T
by Float64
in your examples. Otherwise people might copy past and get an error. –
Violate Try:
m = reshape([],0,2)
or,
m = Array{Float64}(undef, 0, 2)
The second option which explicitly defines type should generate faster code.
A commenter ephemerally suggested using Matrix()
for a 0x0 matrix and Matrix(0,2)
for a 0x2 matrix.
m = Array{Float64, 2}()
. –
Pelargonium It's now much simpler to create empty arrays:
Empty n-dimensional arrays can now be created using multiple semicolons inside square brackets.
julia> m = [;;]
# 0×0 Matrix{Any}
julia> m = [;;;]
# 0×0×0 Array{Any, 3}
Note that this is just syntactic sugar for constructing an uninitialized Array
:
julia/test/syntax.jl#L3143-L3146
@test [] == Array{Any}(undef, 0) @test [;] == Array{Any}(undef, 0) @test [;;] == Array{Any}(undef, 0, 0) @test [;;;] == Array{Any}(undef, 0, 0, 0)
gogo=Array{Any}(undef,0,2)
: gogo[:,1]=go
with go=ones(6)
doesn't seem to work. –
Endamoeba © 2022 - 2024 — McMap. All rights reserved.
gogo=Array{Any}(undef,0,2)
:gogo[:,1]=go
withgo=ones(6)
doesn't seem to work. – Endamoeba