Skip to content

Is it possible to convert a regular vector to a ComponentArray with the specified structure? #159

Answered by ForceBru
ForceBru asked this question in Q&A
Discussion options

You must be logged in to vote

Looks like this is done by ComponentArrays.Axis:

julia> using ComponentArrays
julia> ax = Axis((a = 1, b = ViewAxis(2:7, PartitionedAxis(2, (a = 1, b = 2))), c = ViewAxis(8:10, (a = 1, b = 2:3))));
julia> A = [100, 4, 1.3, 1, 1, 4.4, 0.4, 2, 1, 45];
julia> ca = ComponentArray(A, ax)
ComponentVector{Float64}(a = 100.0, b = [(a = 4.0, b = 1.3), (a = 1.0, b = 1.0), (a = 4.4, b = 0.4)], c = (a = 2.0, b = [1.0, 45.0]))


Yep, this seems to work and even has similar interface to what I envisioned:

julia> example = ComponentArray(a=1, b=5, c=[600,1000])
ComponentVector{Int64}(a = 1, b …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ForceBru
Comment options

@NilsWildt
Comment options

Answer selected by ForceBru
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants