Re: a[[0]] equivalent to a[[-1]] and so forth
- To: mathgroup at smc.vnet.net
- Subject: [mg65167] Re: a[[0]] equivalent to a[[-1]] and so forth
- From: Bill Rowe <readnewsciv at earthlink.net>
- Date: Wed, 15 Mar 2006 23:59:55 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
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