V = [1,2,3]; v .== v' returns boolean matrix?

I find this a bit weird.

julia> v = [1,2,3]; v .== v'
3×3 BitArray{2}:
  true  false  false
 false   true  false
 false  false   true

Why this returns a matrix? I’d expect a simple vector.

The interplay between column and row vectors under broadcasting corresponds to that of nx1 and 1xn arrays. Both arrays get padded to an nxn matrix by repeating columns, respective rows:

julia> v2 = [1 2 3]; v1 = v2'; v1 .== v2
3×3 BitArray{2}:
  true  false  false
 false   true  false
 false  false   true
2 Likes

Out of curiosity, and potentially for the sake of improving our documentation, why did you expect a vector?

2 Likes

I somehow had the (wrong) assumption that broadcast always returned an object whose dimensions matched the dimensions of the at least one of its arguments. Also, I had not been exposed to the new RowVector. These two things confused me, but this example cleared that up.

Perhaps an example in the docs for broadcast using RowVector could help.

1 Like