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

• To: mathgroup at christensen.cybernetics.net
• Subject: [mg568] Re: [mg551] how to pick out alternating columns and rows in a matrix?
• From: villegas (Robert Villegas)
• Date: Sun, 19 Mar 1995 03:57:25 -0600

```> 	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.

Hello Richard,

If you want to pick out rows {r1, ..., rj} and columns {c1, ..., ck} from
the matrix, then Part will do what you want:

Part[u, {r1, ..., rj}, {c1, ..., ck}]

You can use the Range function on Dimensions[u] to generate the odd
indices:

In[15]:= u = Array[a, {6, 6}];

In[16]:= dims = Dimensions[u]

Out[16]= {6, 6}

In[17]:= {rows, columns} = Range[1, #, 2]& /@ dims

Out[17]= {{1, 3, 5}, {1, 3, 5}}

In[18]:= Part[u, rows, columns]

Out[18]= {{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]}}

You can give a list of indices to Part for each dimension of the tensor,
rank 2 or whatever.

Regards,

Robby Villegas

```

• Prev by Date: Re: how to pick out alternating columns and rows in a matrix?
• Next by Date: Re: (-1)^(3/4) -> (-1+I)/Sqrt[2]
• 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?