[Numpy-discussion] creating column vectors

Christopher Barker Chris.Barker at noaa.gov
Wed Feb 8 14:01:02 CST 2006


Stefan van der Walt wrote:
> This is probably a silly question, but what is the best way of
> creating column vectors?

I do this:
 >>> import numpy as N
 >>> v = N.arange(10)
 >>> v
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
 >>> v.shape = (-1,1)
 >>> v
array([[0],
        [1],
        [2],
        [3],
        [4],
        [5],
        [6],
        [7],
        [8],
        [9]])



>  'arange' always returns a row vector

no, it doesn't, it returns a 1-dimensional vector.

> Numpy-masters: Is there a way to set a user- or project-specific config
> switch or something like that to always get matrix results when dealing
> with 1d and 2d arrays? I think that would make numpy much more
> attractive for people like Stefan and me coming from the 2d world.

numpy is not a Matlab clone, nor should it be. That's exactly why I use 
it! Take a little time to get used to it, and you'll become very glad 
that numpy works the way it does, rather than like Matlab.

-Chris




-- 
Christopher Barker, Ph.D.
Oceanographer
                                     		
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov




More information about the Numpy-discussion mailing list