Extracting column vectors from matrix.
Say that I have a rank-2 array (matrix) of shape (m,n). Call it A. When extracting column vectors from A, I often want to keep the result as a rank-2 column vector (for subsequent matrix multiplications, etc), so I usually end up writing something ugly like this: column_vector = reshape(A[:,col],(m,1)) I've got a function to wrap this, but is there a builtin (or cleaner) way to do this sort of operation? TIA. Andrew.
On Thursday 04 September 2003 11:58, Andrew Nesbit wrote:
Say that I have a rank-2 array (matrix) of shape (m,n). Call it A.
When extracting column vectors from A, I often want to keep the result as a rank-2 column vector (for subsequent matrix multiplications, etc), so I usually end up writing something ugly like this:
column_vector = reshape(A[:,col],(m,1))
I've got a function to wrap this, but is there a builtin (or cleaner) way to do this sort of operation?
1) A[:, col:col+1] or perhaps 2) A[:, col][:, NewAxis] Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@cnrs-orleans.fr Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais -------------------------------------------------------------------------------
participants (2)
-
Andrew Nesbit
-
Konrad Hinsen