First row of matrix as 1*n vector

When I subset the first row of a matrix, I would like to make it a 1n vector instead of a n1 vector

f = [1 2 3; # 3×3 Array
    3 4 5;
    6 7 8]

f[1, :]  # first row 3×1 array
f[1:2, :] # first 2 rows 2×3 array
f[:, 1] # first column 3×1 array

Intuitively, the first row of a matrix times the first column of the matrix should make sense, like this


f[1, :] * f[:, 1]

But I have to do this:


f[1, :] ' * f[:, 1]
1 Like

f[1:1, :]

Thanks, but why f[1, :] does not work as f[1:1, :].

See the discussion at https://github.com/JuliaLang/julia/issues/231

You can also do array[1,:]'

why f[:, 1] does not have to be f[:, 1:1]

What do you mean? FWIW,

is wrong.

The correct version is

f[1, :]  # first row 3 array
f[1:2, :] # first 2 rows 2×3 array
f[:, 1] # first column 3 array

There is no x1 there.

3 Likes