Behaviour of |> transpose applied to BitVector

Inputing 1:3 .== 1:3 will return a BitVector of the form 1 1 1 as a column vector

If we set A = 1:3 .== 1:3 and take transpose(A) we get the typical transpose i.e. given as a row vector.

However, if we input 1:3 .== 1:3 |> transpose we receive a 3x3 matrix with ones along the diagonal. I understand why there is 1’s along the diagonal and 0’s elsewhere, but I’m curious why the difference in return evaluation.

I am curious as to why this is if someone could explain?

I’m not at a computer so I can’t check, but I suspect this is due to |> having higher precedence than ==. The broadcast then expands the singleton dimensions, resulting in a matrix.

You can check with Meta.@parse what ends up plugged into where.

1 Like

Right.

julia> dump(:(1:3 .== 1:3 |> transpose))
Expr
  head: Symbol call
  args: Array{Any}((3,))
    1: Symbol .==
    2: Expr
      head: Symbol call
      args: Array{Any}((3,))
        1: Symbol :
        2: Int64 1
        3: Int64 3
    3: Expr
      head: Symbol call
      args: Array{Any}((3,))
        1: Symbol |>
        2: Expr
          head: Symbol call
          args: Array{Any}((3,))
            1: Symbol :
            2: Int64 1
            3: Int64 3
        3: Symbol transpose

What you want is (1:3 .== 1:3) |> transpose

2 Likes