Convert row vector to column vector in NumPy

The easier way is

vector1 = matrix1[:,0:1]

For the reason, let me refer you to another answer of mine:

When you write something like a[4], that’s accessing the fifth element of the array, not giving you a view of some section of the original array. So for instance, if a is an array of numbers, then a[4] will be just a number. If a is a two-dimensional array, i.e. effectively an array of arrays, then a[4] would be a one-dimensional array. Basically, the operation of accessing an array element returns something with a dimensionality of one less than the original array.

Leave a Comment