MathGroup Archive 1995

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Summary:Ways to get Odd Columns&Rows of Matrix

  • To: mathgroup at
  • Subject: [mg715] Re: Summary:Ways to get Odd Columns&Rows of Matrix
  • From: Count Dracula <lk3a at>
  • Date: Tue, 11 Apr 1995 13:25:08 GMT
  • Organization: University of Virginia

In Message-ID: <3m6mj3$qnu at> Robby Villegas wrote:

>I think this general coding will work for higher tensors.  The levels of
>the tensor get rotated around a full cycle, and end up where they were

> everyother[tensor_List] :=
>  With[{n = TensorRank[tensor]},
>   Nest[Transpose[Part[#, Range[1, Length[#], 2]], RotateRight @ Range[n]]&,         
>     tensor, n]
>      ]

This somewhat baroque function is equivalent to the simpler:

  odd[tensor_List] := Part[ tensor, Sequence @@ (Range[1, #, 2] &) /@ Dimensions[tensor] ]

The simpler function also works for any tensor and it is faster. The 
built-in optimized functionality of Part used with several indexing
lists is used in odd, but not in everyother. As Robby Villegas points
out, everyother is not meant as a practical solution.

In[3]:= u = Array[a, {5, 11, 20, 27}];

In[4]:= Timing[odd[u]][[1]]

Out[4]= 0.06 Second

In[5]:= Timing[everyother[u]][[1]]

Out[5]= 1.67 Second

In[6]:= everyother[u]==odd[u]

Out[6]= True

 Levent Kitis           lk3a at    lk3a at
 University of Virginia  Department of Mechanical, Aerospace and Nuclear Engineering  

  • Prev by Date: Re: Lyapunov Equation
  • Next by Date: mixed-font axis labels?
  • Previous by thread: Re: Summary:Ways to get Odd Columns&Rows of Matrix
  • Next by thread: WWW sites