       Re: how to pick out alternating columns and rows in a matrix?

• To: mathgroup at christensen.cybernetics.net
• Subject: [mg574] Re: [mg551] how to pick out alternating columns and rows in a matrix?
• From: bob Hanlon <hanlon at pafosu2.hq.af.mil>
• Date: Sun, 19 Mar 1995 13:42:43

```Here is an approach.

Bob Hanlon

---------------

n = 5;  u = Array[a, {2n, 2n}];
Fold[ Transpose[ Fold[ Drop, #,
Table[ {-k}, {k, Length[ u ]/2} ] ] ]&,
u, {1, 2} ] // MatrixForm
(*  Select odd rows and columns from square matrix  *)

a[1, 1]   a[1, 3]   a[1, 5]   a[1, 7]   a[1, 9]

a[3, 1]   a[3, 3]   a[3, 5]   a[3, 7]   a[3, 9]

a[5, 1]   a[5, 3]   a[5, 5]   a[5, 7]   a[5, 9]

a[7, 1]   a[7, 3]   a[7, 5]   a[7, 7]   a[7, 9]

a[9, 1]   a[9, 3]   a[9, 5]   a[9, 7]   a[9, 9]

n = 4;  u = Array[a, {2n, 2n}];
Fold[ Transpose[ Fold[ Drop, #,
Table[ {-k-1}, {k, Length[ u ]/2} ] ] ]&,
u, {1, 2} ] // MatrixForm
(*  Select even rows and columns from square matrix  *)

a[2, 2]   a[2, 4]   a[2, 6]   a[2, 8]

a[4, 2]   a[4, 4]   a[4, 6]   a[4, 8]

a[6, 2]   a[6, 4]   a[6, 6]   a[6, 8]

a[8, 2]   a[8, 4]   a[8, 6]   a[8, 8]

m = 4;  n = 2;  u = Array[a, {2m, 2n}];
Transpose[ Fold[ Drop, Transpose[ Fold[ Drop, u,
Table[ {-k}, {k, Length[ u ]/2} ] ] ],
Table[ {-k}, {k, Length[ u[] ]/2} ] ] ] // MatrixForm
(*  Select odd rows and columns from even matrix  *)

a[1, 1]   a[1, 3]

a[3, 1]   a[3, 3]

a[5, 1]   a[5, 3]

a[7, 1]   a[7, 3]

m = 3;  n = 5;  u = Array[a, {2m, 2n}];
Transpose[Fold[Drop, Transpose[Fold[Drop, u,
Table[{-k-1}, {k, Length[ u ]/2}] ]],
Table[{-k-1}, {k, Length[ u[] ]/2}] ]] // MatrixForm
(*  Select even rows and columns from even matrix  *)

a[2, 2]    a[2, 4]    a[2, 6]    a[2, 8]    a[2, 10]

a[4, 2]    a[4, 4]    a[4, 6]    a[4, 8]    a[4, 10]

a[6, 2]    a[6, 4]    a[6, 6]    a[6, 8]    a[6, 10]

---------------

On Wed, 15 Mar 1995, Richard Q. Chen wrote:

>
> 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:= MatrixForm[u=Array[a,{6,6}]]
>
> Out//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:= First /@ Partition[Flatten[u],2];
>
> In:= Transpose[Partition[%,3]];
>
> In:= First /@ Partition[Flatten[%],2];
>
> In:= Transpose[Partition[%,3]];
>
> In:= MatrixForm[%]
>
> Out//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
>

```

• Prev by Date: Re: how to pick out alternating columns and rows in a matrix?
• Next by Date: Re: Functions, Part 1
• Previous by thread: Re: how to pick out alternating columns and rows in a matrix?
• Next by thread: Re: how to pick out alternating columns and rows in a matrix?