[Numpy-discussion] beginner question: rank-1 arrays
Stefan van der Walt
stefan@sun.ac...
Mon Oct 8 17:15:46 CDT 2007
On Mon, Oct 08, 2007 at 11:00:39PM +0100, Robin wrote:
> Hi,
>
> I am trying to implement a project in scipy. I think I am getting somewhere
> finally.
>
> However in my code (I am converting from MATLAB) it is important to maintain 2d
> arrays, and keep the difference between row and column vectors. After working
> through some initial problems I think I am getting more of a picture of how
> things work in numpy.
>
> However I am finding my code littered with things like:
> np.array(np.r_[0:nterms],ndmin=2) (for a row vector)
> or
> np.array(np.r_[0:nterms],ndmin=2).T (for a column vector)
You can use
N.arange(10).reshape(-1,1)
or
N.c_[:10,]
But if you use this sort of thing often, just write your own factory
method:
def col(n):
return N.arange(n).reshape(-1,1)
Cheers
Stéfan
More information about the Numpy-discussion
mailing list