[Numpy-discussion] How to Keep An Array Two Dimensional

2012-11-25 Thread Tom Bennett
Hi, I am trying to extract n columns from an 2D array and then operate on the extracted columns. Below is the code: A is an MxN 2D array. u = A[:,:n] #extract the first n columns from A B = np.dot(u, u.T) #take outer product. This code works when n1. However, when n=1, u becomes an 1D array

Re: [Numpy-discussion] How to Keep An Array Two Dimensional

2012-11-25 Thread Warren Weckesser
On Sun, Nov 25, 2012 at 8:24 PM, Tom Bennett tom.benn...@mail.zyzhu.netwrote: Hi, I am trying to extract n columns from an 2D array and then operate on the extracted columns. Below is the code: A is an MxN 2D array. u = A[:,:n] #extract the first n columns from A B = np.dot(u, u.T)

Re: [Numpy-discussion] How to Keep An Array Two Dimensional

2012-11-25 Thread Tom Bennett
Thanks for the quick response. Ah, I see. There is a difference between A[:,:1] and A[:,0]. The former returns an Mx1 2D array whereas the latter returns an M element 1D array. I was using A[:,0] in the code but A[:,:1] in the example. On Sun, Nov 25, 2012 at 8:35 PM, Warren Weckesser

Re: [Numpy-discussion] How to Keep An Array Two Dimensional

2012-11-25 Thread David Warde-Farley
On Sun, Nov 25, 2012 at 9:47 PM, Tom Bennett tom.benn...@mail.zyzhu.net wrote: Thanks for the quick response. Ah, I see. There is a difference between A[:,:1] and A[:,0]. The former returns an Mx1 2D array whereas the latter returns an M element 1D array. I was using A[:,0] in the code but