rafaqz / DimensionalData.jl

Named dimensions and indexing for julia arrays and other data
https://rafaqz.github.io/DimensionalData.jl/stable/
MIT License
281 stars 41 forks source link

Indexing with CartesianIndices returns `Matrix` #408

Closed mauro3 closed 2 years ago

mauro3 commented 2 years ago

julia> A = rand(X(5), Y(5))
5×5 DimArray{Float64,2} with dimensions: X , Y 
 0.124183   0.0896033  0.488964  0.460805    0.58787
 0.930085   0.337978   0.426887  0.224381    0.330103
 0.0922713  0.940475   0.524909  0.977084    0.81439
 0.359208   0.3621     0.043394  0.00822474  0.48672
 0.166133   0.953145   0.777263  0.336801    0.0893465

julia> A[1:2,1:2]
2×2 DimArray{Float64,2} with dimensions: X , Y 
 0.124183  0.0896033
 0.930085  0.337978

julia> A[CartesianIndices((1:2,1:2))]
2×2 Matrix{Float64}:
 0.124183  0.0896033
 0.930085  0.337978

I would expect that the last should return a DimArray too.

rafaqz commented 2 years ago

Ah yes that should work, just missing an implementation.