# Multi-arguments mapslices

**URL:** <https://discourse.julialang.org/t/multi-arguments-mapslices/96172>\
**Category:** General Usage\
**Created:** [March 16, 2023, 10:17am UTC](https://discourse.julialang.org/t/multi-arguments-mapslices/96172 "2023-03-16T10:17:54Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![fabiangans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fabiangans/32/2624_2.png) [@fabiangans](https://discourse.julialang.org/u/fabiangans)\
**Post date:** [March 16, 2023, 10:37am UTC](https://discourse.julialang.org/t/multi-arguments-mapslices/96172/2 "2023-03-16T10:37:22Z")

</div>

I think you can solve this using LazyArrays.jl:

```julia
using LazyArrays
reduce(+, @~(A.*B), dims=1,init=0.0)

```

For reference, I am linking a few related topics:

> [@Is there something like broadcast\_mapreduce?](https://discourse.julialang.org/t/is-there-something-like-broadcast-mapreduce/6076/15):
>
> Just in case someone stumbles upon this thread and to answer my own question. Today I thought about the problem again and I found a nice and fast way to do this by using the mutating broadcast! on a custom AbstractArray which does the reduction upon calling setindex! Here is my final implementation of broadcast\_reduce which has no allocations and is faster than the allocating version: #Define abstract Array which consumes values on setindex! type ArrayReducer{T,N,F} \<: AbstractArray{T,N} v:…

> [@Non-allocating reduced broadcast?](https://discourse.julialang.org/t/non-allocating-reduced-broadcast/23634/2):
>
> There is [https://github.com/JuliaLang/julia/pull/31020](https://github.com/JuliaLang/julia/pull/31020) which is blocked by [https://github.com/JuliaLang/julia/issues/19198](https://github.com/JuliaLang/julia/issues/19198)

> [@Is it possible to do a \`mapreduce\` with multiple arrays while broadcasting over so](https://discourse.julialang.org/t/is-it-possible-to-do-a-mapreduce-with-multiple-arrays-while-broadcasting-over-so/57433):
>
> Is it possible to do a mapreduce with multiple arrays while broadcasting over some dimensions? Something like this U = rand(5, 5, 5) Δ = rand(1, 1, 5) mapreduce((u, Δx) -\> u / Δx, max, U, Δ) where I really want to find the maximum of U[i, j, k] / Δ[k]. Note that the original poster on Slack cannot see your response here on Discourse. Consider transcribing the appropriate answer back to Slack, or pinging the poster here on Discourse so they can follow this thread. [(Original message slack)](https://julialang.slack.com/archives/C6A044SQH/p1616034042074800?thread_ts=1616034042.074800&cid=C6A044SQH) [(…](https://github.com/JuliaCommunity/SlackBridge)

---

_[View the full topic](https://discourse.julialang.org/t/multi-arguments-mapslices/96172)._
