how to pick out alternating columns and rows in a matrix?
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg551] how to pick out alternating columns and rows in a matrix?
- From: Richard Q. Chen <chen at fractal.eng.yale.edu>
- Date: Wed, 15 Mar 95 13:24:59 EST
Hi, Suppose I have a matrix of even dimensions, I would like to form a matrix consisting of only the odd rows and columns of the matrix. A concrete example may make my request clearer: In[2]:= MatrixForm[u=Array[a,{6,6}]] Out[2]//MatrixForm= a[1, 1] a[1, 2] a[1, 3] a[1, 4] a[1, 5] a[1, 6] a[2, 1] a[2, 2] a[2, 3] a[2, 4] a[2, 5] a[2, 6] a[3, 1] a[3, 2] a[3, 3] a[3, 4] a[3, 5] a[3, 6] a[4, 1] a[4, 2] a[4, 3] a[4, 4] a[4, 5] a[4, 6] a[5, 1] a[5, 2] a[5, 3] a[5, 4] a[5, 5] a[5, 6] a[6, 1] a[6, 2] a[6, 3] a[6, 4] a[6, 5] a[6, 6] I would like to pick out the 1st, 3rd and 5th rows and columns. My current solution is embarassingly contorted. I would like to see some more elegant solutions to this. Here is what I did: In[3]:= First /@ Partition[Flatten[u],2]; In[4]:= Transpose[Partition[%,3]]; In[5]:= First /@ Partition[Flatten[%],2]; In[6]:= Transpose[Partition[%,3]]; In[7]:= MatrixForm[%] Out[7]//MatrixForm= a[1, 1] a[1, 3] a[1, 5] a[3, 1] a[3, 3] a[3, 5] a[5, 1] a[5, 3] a[5, 5] Thanks for any help. Richard