UpTo[n]
represents up to n objects or positions. If n objects or positions are available, all are used. If fewer are available, only those available are used.
UpTo
UpTo[n]
represents up to n objects or positions. If n objects or positions are available, all are used. If fewer are available, only those available are used.
Details
- UpTo is used in functions such as Take, Partition and Eigenvalues that require or allow requesting a specific number of elements to use or return.
Examples
open all close allBasic Examples (7)
Take up to the number of elements available:
Take[{a, b, c, d}, UpTo[6]]Take[{a, b, c, d}, UpTo[2]]Drop up to the number of elements available:
Drop[{a, b, c, d}, UpTo[6]]Take up to the number of elements available, dropping what remains, if anything:
TakeDrop[{a, b, c, d}, UpTo[6]]Partition into blocks that are up to 3 elements long; the last block is shorter:
Partition[Range[10], UpTo[3]]Give the 10 most common elements, or as many as are available:
Commonest[RandomInteger[{0, 5}, 15], UpTo[10]]Give the order of the 10 smallest elements, or as many as are available:
Ordering[RandomInteger[{0, 5}, 5], UpTo[10]]Give the maximum height and width of a graphic:
Table[Graphics[Circle[], Background -> LightGreen, ImageSize -> UpTo[100], AspectRatio -> n], {n, {0.5, 1, 2}}]Scope (7)
Take up to 20 characters from a string:
StringTake["abcdefghijklm", UpTo[20]]Find the 4 largest eigenvalues in a matrix, or as many as there are if fewer:
Eigenvalues[Table[N[1 / (i + j + 1)], {i, 3}, {j, 3}], UpTo[4]]Create a "ragged" partition where last elements can be shorter:
Partition[{a, b, c, d, e, f, g}, UpTo[3]]Partition[{a, b, c, d, e, f, g}, UpTo[3], 1]Obtain the 6 most common elements, or as many as there are if fewer:
Commonest[{b, a, c, 2, a, b, 1, 2}, UpTo[6]]Generate a random sample of up to 6 elements, or as many as there are if fewer:
RandomSample[Range[5], UpTo[6]]Obtain the first 4 minimal elements, or as many as are available:
MinimalBy[{{a, 1}, {b, 1}, {b, 3}}, First, UpTo[4]]Partition an image so that lengths are up to 36 pixels and heights are up to 28 pixels:
Grid[ImagePartition[[image], {UpTo[36], UpTo[28]}]]Properties & Relations (2)
Cases behaves as though it implicitly uses UpTo:
Cases[{1, "f", g, "h", "j"}, _ ? StringQ, 1, 4]You can give an explicit UpTo specification to Cases:
Cases[{1, "f", g, "h", "j"}, _ ? StringQ, 1, UpTo[4]]ImageTake behaves as though it implicitly uses UpTo:
i1 = ImageTake[[image], 200]You can give an explicit UpTo specification to ImageTake:
i2 = ImageTake[[image], UpTo[200]]i1 === i2Related Guides
History
Text
Wolfram Research (2015), UpTo, Wolfram Language function, https://reference.wolfram.com/language/ref/UpTo.html.
CMS
Wolfram Language. 2015. "UpTo." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/UpTo.html.
APA
Wolfram Language. (2015). UpTo. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/UpTo.html
BibTeX
@misc{reference.wolfram_2026_upto, author="Wolfram Research", title="{UpTo}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/UpTo.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_upto, organization={Wolfram Research}, title={UpTo}, year={2015}, url={https://reference.wolfram.com/language/ref/UpTo.html}, note=[Accessed: 13-June-2026]}