# AxisArrays, iterate over all dimensions except certain ones?

**URL:** <https://discourse.julialang.org/t/axisarrays-iterate-over-all-dimensions-except-certain-ones/28487>\
**Category:** General Usage\
**Created:** [September 6, 2019, 10:47pm UTC](https://discourse.julialang.org/t/axisarrays-iterate-over-all-dimensions-except-certain-ones/28487 "2019-09-06T22:47:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tlnagy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlnagy/32/5815_2.png) [@tlnagy](https://discourse.julialang.org/u/tlnagy)\
**Post date:** [September 6, 2019, 10:47pm UTC](https://discourse.julialang.org/t/axisarrays-iterate-over-all-dimensions-except-certain-ones/28487/1 "2019-09-06T22:47:43Z")

</div>

Is there an easy way to iterate over all axes _except_ certain ones? I.e. the negation of the inputs? My use case is a general function that works on images with an arbitrary number of dimensions, but needs to iterate over all XY slices.

Here’s a super clunky way that I just whipped up to show what I was generally thinking:

```julia
using AxisArrays
# this is given to us and the axis number/order is not guaranteed
mat = AxisArray(rand(10, 10, 3, 10), :x, :y, :channel, :time);

all_axs = Set(axisnames(mat))
pop!(all_axs, :x)
pop!(all_axs, :y)
axs = collect(all_axs)
for I in CartesianIndices(Tuple(size(mat, Axis{ax}) for ax in axs))
    println(collect(Axis{ax}(I[i]) for (i, ax) in enumerate(axs)))
end

```

What’s a better way to accomplish this?

---

<div class="post-metadata">

**Author:** ![tlnagy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlnagy/32/5815_2.png) [@tlnagy](https://discourse.julialang.org/u/tlnagy)\
**Post date:** [September 19, 2019, 7:08pm UTC](https://discourse.julialang.org/t/axisarrays-iterate-over-all-dimensions-except-certain-ones/28487/2 "2019-09-19T19:08:30Z")

</div>

bump?

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [September 19, 2019, 9:53pm UTC](https://discourse.julialang.org/t/axisarrays-iterate-over-all-dimensions-except-certain-ones/28487/3 "2019-09-19T21:53:38Z")

</div>

You could do `eachslice` twice to iterate the slices directly. But AxisArrays doesn’t support it.

DimensionalData.jl and NamedDims.jl do (but aren’t as polished as AxisArrays in other ways yet). I’ll think about adding multi dim eachslice to DimensionalData.jl it seems useful.
