[Numpy-discussion] force column vector

Alexander Schmolck a.schmolck at gmx.net
Wed Feb 7 08:08:01 EST 2007


Christian <ckkart at hoc.net> writes:

> Hi,
> 
> when creating an ndarray from a list, how can I force the result to be
> 2d *and* a column vector? So in case I pass a nested list, there will be no
> modification of the shape and when I pass a simple list, it will be 
> converted to a 2d column vector. I can only think of a solution using 'if'
> clauses but I suppose there is a more elegant way.

This will always return a column vector, but I'm not sure from you description
if that's what you want (do you want [[1,2,3]] etc. to come out as a row-vector?)

    In [8]: ravel(array([1,2,3]))[:,newaxis]
    Out[8]: 
    array([[1],
           [2],
           [3]])

'as



More information about the NumPy-Discussion mailing list