The vector you are creating is neither row nor column. It actually has 1 dimension only. You can verify that by
myvector.ndim
which is 1
myvector.shape
, which is (3,)
(a tuple with one element only). For a row vector is should be (1, 3)
, and for a column (3, 1)
Two ways to handle this
reshape
your current oneYou can explicitly create a row or column
row = np.array([ # one row with 3 elements
[1, 2, 3]
]
column = np.array([ # 3 rows, with 1 element each
[1],
[2],
[3]
])
or, with a shortcut
row = np.r_['r', [1,2,3]] # shape: (1, 3)
column = np.r_['c', [1,2,3]] # shape: (3,1)
Alternatively, you can reshape it to (1, n)
for row, or (n, 1)
for column
row = my_vector.reshape(1, -1)
column = my_vector.reshape(-1, 1)
where the -1
automatically finds the value of n
.