# \#mapslices

**URL:** https://discourse.julialang.org/tag/mapslices/1085.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Understanding map/mapslices/eachslice/stack](https://discourse.julialang.org/t/understanding-map-mapslices-eachslice-stack/132744)

<div class="topic-metadata">

**Author:** [@Boris](https://discourse.julialang.org/u/Boris)\
**Replies:** 2\
**Last updated:** [September 29, 2025, 2:22pm UTC](https://discourse.julialang.org/t/understanding-map-mapslices-eachslice-stack/132744 "2025-09-29T14:22:49Z")

</div>

Hi, I’ve been trying to learn to use mapslices and don’t understand the synthax/errors for my use case. Suppose I have # MWE sb = \[true false false; false false false; true true true\] # dimensions (k \\times j) yh = ran…

---

## [Broadcasting functions with multiple arguments in same dimension using Mapslices](https://discourse.julialang.org/t/broadcasting-functions-with-multiple-arguments-in-same-dimension-using-mapslices/114586)

<div class="topic-metadata">

**Author:** [@chihlun](https://discourse.julialang.org/u/chihlun)\
**Replies:** 14\
**Last updated:** [May 22, 2024, 11:41pm UTC](https://discourse.julialang.org/t/broadcasting-functions-with-multiple-arguments-in-same-dimension-using-mapslices/114586 "2024-05-22T23:41:42Z")

</div>

Hi everyone, I have a simple code as shown below. Both a and y are 4D matrices. I want the function f(x, y) to operate on the third dimension, summing the x matrix along the 3rd dimension, summing the y matrix along the…

---

## [Mapslices and @threads](https://discourse.julialang.org/t/mapslices-and-threads/28138)

<div class="topic-metadata">

**Author:** [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Replies:** 4\
**Last updated:** [January 11, 2024, 4:57pm UTC](https://discourse.julialang.org/t/mapslices-and-threads/28138 "2024-01-11T16:57:17Z")

</div>

I am fooling around with 1.30-rc1 and would like to understand how to make a call on mapslices threaded. Since mapslices can emulate a loop over an array dimension, it would nice to make that “loop” Threads.@threads. Do…

---

## [How to sum the result of mapslices on the GPU while tracking gradients?](https://discourse.julialang.org/t/how-to-sum-the-result-of-mapslices-on-the-gpu-while-tracking-gradients/105310)

<div class="topic-metadata">

**Author:** [@taotree](https://discourse.julialang.org/u/taotree)\
**Replies:** 0\
**Last updated:** [October 23, 2023, 11:52am UTC](https://discourse.julialang.org/t/how-to-sum-the-result-of-mapslices-on-the-gpu-while-tracking-gradients/105310 "2023-10-23T11:52:49Z")

</div>

I need to do mapslices but need it to support gradient tracking for Zygote. So, I’m trying to use SliceMap.slicemap. I can’t use SliceMap.mapcols because I have parameters inside the function. SliceMap.slicemap returns a…

---

## [How to use Zygote.gradient where mapslices uses a function that includes a parameter?](https://discourse.julialang.org/t/how-to-use-zygote-gradient-where-mapslices-uses-a-function-that-includes-a-parameter/105307)

<div class="topic-metadata">

**Author:** [@taotree](https://discourse.julialang.org/u/taotree)\
**Replies:** 1\
**Last updated:** [October 23, 2023, 11:07am UTC](https://discourse.julialang.org/t/how-to-use-zygote-gradient-where-mapslices-uses-a-function-that-includes-a-parameter/105307 "2023-10-23T11:07:40Z")

</div>

Original post below. I found the documentation for SliceMap.mapcols which explicitly states this isn’t supported: Note that if f itself contains parameters, their gradients are also not tracked.. So… if I need to do maps…

---

## [CUDA on slices](https://discourse.julialang.org/t/cuda-on-slices/86782)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 5\
**Last updated:** [September 6, 2022, 2:45am UTC](https://discourse.julialang.org/t/cuda-on-slices/86782 "2022-09-06T02:45:33Z")

</div>

Trying to apply a function to slices of a CuArray. Tried broadcasting, mapslices and various Tensor packages. Is there any way to do this? using CUDA, Pipe, Interpolations, TensorCast d = Uniform(1,30) x = Float64.(1…

---

## [Speeding up mapslices](https://discourse.julialang.org/t/speeding-up-mapslices/61907)

<div class="topic-metadata">

**Author:** [@nandoconde](https://discourse.julialang.org/u/nandoconde)\
**Replies:** 0\
**Last updated:** [May 27, 2021, 9:01am UTC](https://discourse.julialang.org/t/speeding-up-mapslices/61907 "2021-05-27T09:01:28Z")

</div>

Hello! I was trying to perform a matrix inversion in a 3-D array along the third dimension (more info here) and reached two possible solutions. First solution – Manual inversion I am not worrying too much about strange…

---

## [How to map a function over the given axis of a multi-dimension array and return another array?](https://discourse.julialang.org/t/how-to-map-a-function-over-the-given-axis-of-a-multi-dimension-array-and-return-another-array/83586)

<div class="topic-metadata">

**Author:** [@zhangqian](https://discourse.julialang.org/u/zhangqian)\
**Replies:** 4\
**Last updated:** [July 1, 2022, 3:27pm UTC](https://discourse.julialang.org/t/how-to-map-a-function-over-the-given-axis-of-a-multi-dimension-array-and-return-another-array/83586 "2022-07-01T15:27:32Z")

</div>

I am trying to rotate some images, so I want to write something like np.array(list(map(lambda x: rotate(x), images))) in python, where the variable images is an array of shape \[N, H, W\]. Is there a method in julia that…

---

## [Is there a way to "enumerate" \`mapslices\` other than\`\`\`i = 0result = mapslices(m](https://discourse.julialang.org/t/is-there-a-way-to-enumerate-mapslices-other-than-i-0result-mapslices-m/55414)

<div class="topic-metadata">

**Author:** [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Replies:** 3\
**Last updated:** [February 17, 2021, 9:39am UTC](https://discourse.julialang.org/t/is-there-a-way-to-enumerate-mapslices-other-than-i-0result-mapslices-m/55414 "2021-02-17T09:39:06Z")

</div>

Is there a way to “enumerate” mapslices other than i = 0 result = mapslices(myarray; dims=dims) do x i += 1 myfunction(x, i) end ? Note that the original poster on Slack cannot see your response here on Discou…

---

## [Mapslices() warntype?](https://discourse.julialang.org/t/mapslices-warntype/36844)

<div class="topic-metadata">

**Author:** [@tomtom](https://discourse.julialang.org/u/tomtom)\
**Replies:** 4\
**Last updated:** [April 1, 2020, 1:24pm UTC](https://discourse.julialang.org/t/mapslices-warntype/36844 "2020-04-01T13:24:55Z")

</div>

I’m wondered seeing that mapslices() gives warntype as below: julia\> const mat = randn(3,2) 3×2 Array{Float64,2}: 1.49498 -1.98461 -0.935659 -0.0317199 0.783414 -0.284129 julia\> mapslices(prod, mat, dims = …

---

## [Making mapslices drop dimensions for scalars results automatially](https://discourse.julialang.org/t/making-mapslices-drop-dimensions-for-scalars-results-automatially/19624)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 3\
**Last updated:** [October 22, 2019, 6:42pm UTC](https://discourse.julialang.org/t/making-mapslices-drop-dimensions-for-scalars-results-automatially/19624 "2019-10-22T18:42:25Z")

</div>

In a sense, I am looking for a workaround for #16606: for functions which return an array, I would like to keep it as is, but for functions which return a scalar, I would like to drop the relevant dimension. I can’t just…

---

## [Alternative to mapslices that does not allocate slices](https://discourse.julialang.org/t/alternative-to-mapslices-that-does-not-allocate-slices/13820)

<div class="topic-metadata">

**Author:** [@piever](https://discourse.julialang.org/u/piever)\
**Replies:** 8\
**Last updated:** [September 12, 2018, 1:28pm UTC](https://discourse.julialang.org/t/alternative-to-mapslices-that-does-not-allocate-slices/13820 "2018-09-12T13:28:09Z")

</div>

I’m trying to understand whether there is a non-allocating equivalent of mapslices. I often end up needing to reduce sliced views, for example: mapslices(sum, m, dims = n) And I would like to figure out a way that does…

---

## [Bikeshedding mapslices](https://discourse.julialang.org/t/bikeshedding-mapslices/3998)

<div class="topic-metadata">

**Author:** [@bramtayl](https://discourse.julialang.org/u/bramtayl)\
**Replies:** 18\
**Last updated:** [April 14, 2018, 6:49pm UTC](https://discourse.julialang.org/t/bikeshedding-mapslices/3998 "2018-04-14T18:49:52Z")

</div>

I’m trying to improve the performance of mapslices, which is needed for in https://github.com/JuliaLang/julia/issues/3893#issuecomment-304924903. The only changes I’ve made are to rename things so I understand (a little)…
