Span
i;;j
represents a span of elements i through j.
i;;
represents a span from i to the end.
;;j
represents a span from the beginning to j.
;;
represents a span that includes all elements.
i;;j;;k
represents a span from i through j in steps of k.
i;;;;k
represents a span from i to the end in steps of k.
;;j;;k
represents a span from the beginning to j in steps of k.
;;;;k
represents a span from the beginning to the end in steps of k.
Details
- m[[i;;j;;k]] is equivalent to Take[m,{i,j,k}].
- m[[i;;j]]=v can be used to reset a span of elements in a list or other expression.
- When used in Part, negative i and j count from the end.
- In i;;j, i;;j;;k, etc., i and j can be of the form UpTo[n].
- Any argument of Span[…] can be All, in which case it is interpreted as returning the largest possible number of elements consistent with any possible value of that argument.
Examples
open allclose allBasic Examples (3)
Scope (7)
Negative indices count from the end:
A negative step size extracts elements in reverse order:
Take all elements from the third position to the end:
Take the first five characters:
Use UpTo to restrict the right endpoint of the span to the length of the list:
Use UpTo to restrict the left endpoint of the span to the length of the list:
Properties & Relations (4)
All in the first argument of Span is equivalent to the value 1:
All in the second argument of Span is equivalent to the value -1:
All in the third argument of Span is equivalent to the value 1 or -1:
The value is chosen to given a non-empty range:
When operating on the expression expr, UpTo[n] is equivalent to Min[n,Length[expr]]:
Text
Wolfram Research (2007), Span, Wolfram Language function, https://reference.wolfram.com/language/ref/Span.html (updated 2017).
CMS
Wolfram Language. 2007. "Span." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2017. https://reference.wolfram.com/language/ref/Span.html.
APA
Wolfram Language. (2007). Span. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Span.html