[Numpy-discussion] force column vector

Christopher Barker Chris.Barker@noaa....
Wed Feb 7 10:32:36 CST 2007

Christian wrote:
> 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'm not sure I understand the specification of the problem. I would 
think that the definition of a column vector is that it's shape is:


which makes it easy:

def MakeColumn(input):
     a = asarray(input)
     a.shape = (-1,1)
     return a

however, if you want: MakeColumn([[1,2],[3,4],[5,6]])

to return:
array([[1, 2],
        [3, 4],
        [5, 6]])

that's not what I would call a column vector, and if that's what you 
want, then what would you want:


to return?


Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception


More information about the Numpy-discussion mailing list