# Unexpected broadcasting behaviour (?)

**URL:** <https://discourse.julialang.org/t/unexpected-broadcasting-behaviour/124670>\
**Category:** General Usage\
**Created:** [January 11, 2025, 11:36am UTC](https://discourse.julialang.org/t/unexpected-broadcasting-behaviour/124670 "2025-01-11T11:36:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gravlax](https://avatars.discourse-cdn.com/v4/letter/g/dbc845/32.png) [@Gravlax](https://discourse.julialang.org/u/Gravlax)\
**Post date:** [January 11, 2025, 11:36am UTC](https://discourse.julialang.org/t/unexpected-broadcasting-behaviour/124670/1 "2025-01-11T11:36:26Z")

</div>

Hi  
I was wondering if the MWE below yields the expected behaviour.  
Why is the result not symmetric?  
I would have expected symmetric resulting arrays sizes from this.  
Cheers!

```julia
let 
    b = ones(3, 4)
    a = ones(1, 2)
    x = a .* b[2,2:end-1]
    @show size(x)

    b = ones(4, 3)
    a = ones(2, 1)
    x = a .* b[2:end-1,2]
    @show size(x)
end

```

---

<div class="post-metadata">

**Author:** ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)\
**Post date:** [January 11, 2025, 12:36pm UTC](https://discourse.julialang.org/t/unexpected-broadcasting-behaviour/124670/2 "2025-01-11T12:36:23Z")

</div>

You can make sense of it by always considering `Vector`s to be column vectors, i.e. n \times 1 matrices.

```julia-repl
julia> size(rand(1, 2) .* rand(2, 1)) # broadcast to 2x2
(2, 2)

julia> size(rand(1, 2) .* rand(2)) # same
(2, 2)

julia> size(rand(2, 1) .* rand(1, 2)) # broadcast to 2x2
(2, 2)

julia> size(rand(2, 1) .* rand(2)) # same as 2 x 1 .* 2 x 1  
(2, 1)

julia> size(rand(2, 1) .* rand(2, 1))
(2, 1)

```

---

<div class="post-metadata">

**Author:** ![GHTaarn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ghtaarn/32/216007_2.png) [@GHTaarn](https://discourse.julialang.org/u/GHTaarn)\
**Post date:** [January 11, 2025, 12:36pm UTC](https://discourse.julialang.org/t/unexpected-broadcasting-behaviour/124670/3 "2025-01-11T12:36:57Z")

</div>

Is it because what you want is:

```julia
let 
    b = ones(3, 4)
    a = ones(1, 2)
    x = a .* b[2:2,2:end-1]
    @show size(x)

    b = ones(4, 3)
    a = ones(2, 1)
    x = a .* b[2:end-1,2:2]
    @show size(x)
end

```

If an index is an integer rather than a range, then a `Matrix` becomes a `Vector`
