Add Rows or Columns to Matrix by Recycling

Viewed 68

I have a 2x2 matrix

a = [1 2
    3 4]

2×2 Array{Int64,2}:
 1  2
 3  4

and want to add a row of all 0s. I can just do this:

vcat(0, a)

3×2 Array{Int64,2}:
 0  0
 1  2
 3  4

The 0 gets recycled and fills up the entire first row. To me (coming from R) this makes sense.

What does not make sense to me is the following:

hcat(0, a)

ERROR: DimensionMismatch("mismatch in dimension 1 (expected 1 got 2)")

Anyone got an explanation?

1 Answers
Related