MathGroup Archive 2006

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

Search the Archive

Re: a[[0]] equivalent to a[[-1]] and so forth


On 3/15/06 at 6:28 AM, amscosta at uem.br (Alexandre Costa) wrote:

>I have a simple issue: If  I have a list such as : a =
>{4, 5, 6}; How can I do this in an elegant way: a[[0]] equivalent
>to a[[-1]] a[[-1]] equivalent to a[[-2]] and so forth.

>I thought of a[[If[i <=0, i - 1, i]]] would solve the problem but I
>want a more elegant way of doing this.

I admit to some curiosity as to why you want to do this. Another way to achieve the same effect would be

a[[Mod[n,3,1]]]

since

In[5]:=Mod[#1, 3, 1]&/@ Range[-2, 3]

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

This method has the added benefit that it maps any integer into an acceptable value.
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: a[[0]] equivalent to a[[-1]] and so forth
  • Next by Date: Re: ScatterPlot3D with One More Dimension?
  • Previous by thread: Re: a[[0]] equivalent to a[[-1]] and so forth
  • Next by thread: Multiple Selections in Notebook