How to use Mathematica and the Wolfram Langage - for beginner, intermediate, and advanced users.
Showing posts with label Mod. Show all posts
Showing posts with label Mod. Show all posts
Sunday, April 15, 2012
Cyclically Selecting Parts Using Mod with Offset = 1
The Doc Center notes this usage of the offset feature in Mod to cyclically select Parts. Setting offset to 1 means Part will cycle from Part #1 through the value of n instead of the expression itself (i.e. Part #0) tbrough n - 1. However I have not seen a useful application of this idiom.
In[1]:= {a, b, c}[[Mod[Range[10], 3, 1]]]
Out[1]= {a, b, c, a, b, c, a, b, c, a}
Labels:
cyclically selecting parts,
mathematica,
Mod,
Offset,
Part
Subscribe to:
Posts (Atom)