Closed Balinus closed 7 years ago
Right now map
is implemented, so you can do:
julia> aa = AxisArray([1 2; 3 4], Axis{:time}(1:2), Axis{:meas}(1:2))
2-dimensional AxisArray{Int64,2,...} with axes:
:time, 1:2
:meas, 1:2
And data, a 2×2 Array{Int64,2}:
1 2
3 4
julia> map(+, aa, aa)
2-dimensional AxisArray{Int64,2,...} with axes:
:time, 1:2
:meas, 1:2
And data, a 2×2 Array{Int64,2}:
2 4
6 8
You can also preallocate your output and use broadcast!
/.=
:
julia> bb = similar(aa)
2-dimensional AxisArray{Int64,2,...} with axes:
:time, 1:2
:meas, 1:2
And data, a 2×2 Array{Int64,2}:
4507241776 4448405392
4448417008 0
julia> bb .= aa .+ aa
2-dimensional AxisArray{Int64,2,...} with axes:
:time, 1:2
:meas, 1:2
And data, a 2×2 Array{Int64,2}:
2 4
6 8
Operations like broadcast
/.+
are more challenging but could be implemented for at least a subset of argument types (such as axisarrays that share axes as in map
).
Other operations will fall back on generic AbstractArray
implementations, so you'll lose axis information.
broadcast
should not be hard once I finish https://github.com/JuliaLang/julia/pull/23939. I may implement it as a test case to make sure I got the design right. But that will make this package 0.7-only, so we may have to wait before merging.
ok, thanks for all the information. I think I'll be OK with @iamed2 solution. Will keep an eye on broadcasting implementation.
Thanks!
Hello,
I'd like to know if there is a way to do basic operations on AxisArrays, such as addition of two AxisArray that would have the same axes.
Thanks for any info!