Operations on AxisArrays

Adding two axis arrays, with equal axes forgets the axes and results in an ordinary array. Same for other operations. Is this a bug or expected behaviour? Is there a recommended way to apply operations without forgetting the axes?

julia> using AxisArrays

julia> x_axis = Axis{:x}(1:3);

julia> arr = AxisArray(ones(3), x_axis)
1-dimensional AxisArray{Float64,1,...} with axes:
    :x, 1:3
And data, a 3-element Array{Float64,1}:
 1.0
 1.0
 1.0

julia> arr + arr
3-element Array{Float64,1}:
 2.0
 2.0
 2.0

julia> arr .+ arr
3-element Array{Float64,1}:
 2.0
 2.0
 2.0

julia> abs.(arr)
3-element Array{Float64,1}:
 1.0
 1.0
 1.0

julia> -arr
3-element Array{Float64,1}:
 -1.0
 -1.0
 -1.0

julia> Pkg.status("AxisArrays")
 - AxisArrays                    0.2.0

I think that’s just because it hasn’t been implemented yet. FWIW, you can use NamedArrays for now if you need this kind of thing.

1 Like

You might be interested in solutions found in this (closed) issue I started which address this question.

Basic operators on AxisArrays

https://github.com/JuliaArrays/AxisArrays.jl/issues/126

1 Like