In my experience, 1D is the norm in numpy for vectors. The only good reason to save the element vector n as a 2D array of form (1, n) or (n, 1) in the context of linear algebra, where you would like to differentiate row and column vectors. Since EitanT hinted at his now deleted answer, you probably want to use the numpy matrix type, which saves a 2D return form, except for access to one element, for example, if a has the form (m, n) , then a[0] has the form (n,) for the type ndarray , but the form (1, n) for the type matrix , although a[0, 0] returns the scalar in both cases.
If you stick to the 1D shape vector (n,) , you can redo it on the fly to perform certain operations that require a 2D shape:
a.reshape(-1, 1)
Numpy will automatically convert your 1D vectors to form (1, n) when broadcasting for operations with a 2D array.
source share