Hi,<div><br></div><div>I am trying to extract n columns from an 2D array and then operate on the extracted columns. Below is the code:</div><div><br></div><div>A is an MxN 2D array.</div><div><br></div><div>u = A[:,:n] #extract the first n columns from A</div>
<div><br></div><div>B = np.dot(u, u.T) #take outer product.</div><div><br></div><div>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.</div><div><br>
</div><div>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.</div><div><br></div><div>Thanks,</div><div>
Tom</div><div><br></div><div><br></div>