# DimensionalData: how to map slices, while using non-slice dimensions

**URL:** https://discourse.julialang.org/t/dimensionaldata-how-to-map-slices-while-using-non-slice-dimensions/87839
**Category:** Data
**Tags:** question, dimensionaldata
**Created:** [September 26, 2022, 8:55pm UTC](https://discourse.julialang.org/t/dimensionaldata-how-to-map-slices-while-using-non-slice-dimensions/87839 "2022-09-26T20:55:30Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![ElOceanografo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eloceanografo/32/624_2.png) [@ElOceanografo](https://discourse.julialang.org/u/ElOceanografo)
#### Post date: [September 26, 2022, 8:55pm UTC](https://discourse.julialang.org/t/dimensionaldata-how-to-map-slices-while-using-non-slice-dimensions/87839/1 "2022-09-26T20:55:30Z")

</div>

I’ve got a multidimensional `DimArray` and want to map a function that summarizes across one of the dimensions. This is simple to do using `mapslices`, e.g.

```julia
using DimensionalData
arr = rand(X(1:10), Y(1:20), Z(1:30))
f(z) = sum(z)
mapslices(f, arr, dims=:Z)

```

However, I have a function that also depends on the values of `x` and `y` at each slice, something like

```julia
f(x, y, zs) = sin(x) + cos(y) + sum(zs)

```

What’s the best way to map this function across the all the `Z` slices of the array? I’ve got this,

```julia
[f(x, y, arr[X(At(x)), Y(At(y))]) 
    for (x, y) in Iterators.product(collect.(otherdims(arr, :Z))...)]

```

but was hoping there might be a more streamlined solution, preferably one that would generalize for higher-dimensional arrays as well…

---

<div class="post-metadata">

### Author: ![ElOceanografo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eloceanografo/32/624_2.png) [@ElOceanografo](https://discourse.julialang.org/u/ElOceanografo)
#### Post date: [September 26, 2022, 8:59pm UTC](https://discourse.julialang.org/t/dimensionaldata-how-to-map-slices-while-using-non-slice-dimensions/87839/2 "2022-09-26T20:59:45Z")

</div>

Also worked this out, which seems like an improvement. Any better ideas?

```julia
f(coords, zs) = sum(coords) + sum(zs)
dims = otherdims(arr, :Z)
[f(coords, arr[I...]) for (coords, I) in zip(DimPoints(dims), DimKeys(dims))]

```
