# Broadcast strange on \`0-dimensional Array\`?

**URL:** <https://discourse.julialang.org/t/broadcast-strange-on-0-dimensional-array/97311>\
**Category:** General Usage\
**Created:** [April 10, 2023, 5:45pm UTC](https://discourse.julialang.org/t/broadcast-strange-on-0-dimensional-array/97311 "2023-04-10T17:45:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [April 10, 2023, 5:45pm UTC](https://discourse.julialang.org/t/broadcast-strange-on-0-dimensional-array/97311/1 "2023-04-10T17:45:58Z")

</div>

I stumbled over a small thing that surprised me. Assume we have a Szenario where we want to be able to have mutating functions, but we came along with floats. We could just turn them into 0-Arrays using `fill(0.0)`. I was surprised about the following behaviour:

What I am used to do (for arbitrary arrays but here just for `1`-dimensional arrays with one element)

```julia
julia> 1.0 .* [1.0]
1-element Vector{Float64}:
 1.0

julia> 1.0 * [1.0]
1-element Vector{Float64}:
 1.0

```

(or similarly `.+` and `+` when I add two of these.

However when I use `fill` (0-dim arrays) I get

```julia
julia> 1.0 * fill(1.0)
0-dimensional Array{Float64, 0}:
1.0

julia> 1.0 .* fill(1.0) # <-- Why?
1.0

```

The same happens even for `+` vs `.+` for `fill(0.0)`s – where especially

```julia
julia> fill(0.0) .+ fill(1.0)
1.0

```

Seems quite surprising to me, I would have expected a `0-dimensioal Array{Float64,0}` for both broadcast operations here.

Can someone explain this behaviour?

For the largest context, see [this PR](https://github.com/JuliaManifolds/Manopt.jl/pull/236), where I try to be able to provide an interface for optimization on the real line (where a user might think in ` p=1.0` floats and not `p=[1.0]` arrays)

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [April 10, 2023, 5:56pm UTC](https://discourse.julialang.org/t/broadcast-strange-on-0-dimensional-array/97311/2 "2023-04-10T17:56:40Z")

</div>

possibly relevant: [broadcast should not drop zero-dimensional results to scalars · Issue #28866 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/28866)

---

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [April 10, 2023, 6:05pm UTC](https://discourse.julialang.org/t/broadcast-strange-on-0-dimensional-array/97311/3 "2023-04-10T18:05:41Z")

</div>

Wow! Super-fast reply, thanks!  
So I will probably stick to using `[1.0]` instead of `fill(1.0)`, since those 1-dim arrays behave much more as I expect arrays to behave.
