0

I know the simple/worked solution to this question is reshape (-1, 1) for turning row vector (numpy.array) into a column vector (numpy.array).

Specifically, I want to understand why numpy.transpose(a) won't work.

Say,

vector_of_1 = np.transpose(np.ones(N)) # statement 1

And if I define a column vector b, and use the following statement:

V = b + vector_of_1 

I would get a weird matrix V.

My fix is to use

vector_of_1 = np.ones(N).reshape(-1,1)

And it works as expected (V being a column vector).

But I want to understand why the transpose method (i.e., statement 1) won't work. Detailed explanation is appreciated.

Xu Siyuan
  • 27
  • 7
  • 2
    `np.transpose` has a clear statement: `Transposing a 1-D array returns an unchanged view of the original array.` `transpose` changes the order of the dimensions. With just one dimension, there's nothing to change. Shape (3,)=>(3,). For 2d (2,3)=>(3,2). You are reading too much of the linear algebra "row vector" vs "column vector" distinction into `numpy`. – hpaulj Jan 06 '23 at 20:35

0 Answers0