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 n>1. However, when n=1, u becomes an 1D array instead
of an Mx1 2D array and the code breaks down.

I wonder if there is any way to keep u=A[:,:n] an Mxn array no matter what
value n takes. I do not want to use matrix because array is more convenient
in other places.

Thanks,
Tom
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to