# How to broadcast for 3d-array?

**URL:** <https://discourse.julialang.org/t/how-to-broadcast-for-3d-array/113581>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [April 28, 2024, 7:33am UTC](https://discourse.julialang.org/t/how-to-broadcast-for-3d-array/113581 "2024-04-28T07:33:47Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![ederag](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ederag/32/4106_2.png) [@ederag](https://discourse.julialang.org/u/ederag)\
**Post date:** [April 28, 2024, 8:18am UTC](https://discourse.julialang.org/t/how-to-broadcast-for-3d-array/113581/2 "2024-04-28T08:18:42Z")

</div>

You might be interested in [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757),  
which shows how to use triple back-quotes to format code.

> I want the element specified by [i,j,k] in the three-dimensional array to be the value when the i,j,kth element of each argument is assigned to the function.

This is something that can be done neatly with [comprehensions](https://docs.julialang.org/en/v1/manual/arrays/#man-comprehensions)  
rather than broadcasting:

```julia-repl
julia> v = [0.1, 0.2, 0.3, 0.4]

julia> func(a, b, c) = sin(a + b + c)

julia> [func(a, b, c) for a in v, b in v, c in v]
4×4×4 Array{Float64, 3}:
[:, :, 1] =
 0.29552 0.389418 0.479426 0.564642
 0.389418 0.479426 0.564642 0.644218
 0.479426 0.564642 0.644218 0.717356
 0.564642 0.644218 0.717356 0.783327

[:, :, 2] =
 0.389418 0.479426 0.564642 0.644218
 0.479426 0.564642 0.644218 0.717356
 0.564642 0.644218 0.717356 0.783327
 0.644218 0.717356 0.783327 0.841471

[:, :, 3] =
 0.479426 0.564642 0.644218 0.717356
 0.564642 0.644218 0.717356 0.783327
 0.644218 0.717356 0.783327 0.841471
 0.717356 0.783327 0.841471 0.891207

[:, :, 4] =
 0.564642 0.644218 0.717356 0.783327
 0.644218 0.717356 0.783327 0.841471
 0.717356 0.783327 0.841471 0.891207
 0.783327 0.841471 0.891207 0.932039

```

---

_[View the full topic](https://discourse.julialang.org/t/how-to-broadcast-for-3d-array/113581)._
