Apply 
Details and Options
- Apply uses standard level specifications:
-
n levels 1 through n Infinity levels 1 through Infinity {n} level n only {n1,n2} levels n1 through n2 - The default value for levelspec in Apply is {0}.
- Apply[f,expr,{1}] is equivalent to MapApply[f,expr] or f@@@expr. »
- A positive level n consists of all parts of expr specified by n indices.
- A negative level -n consists of all parts of expr with depth n.
- Level -1 consists of numbers, symbols, and other objects that do not have subparts.
- Level 0 corresponds to the whole expression.
- With the option setting Heads->True, Apply will apply inside the heads of parts in addition to the parts themselves. »
- Apply always effectively constructs a complete new expression and then evaluates it.
- Apply operates on SparseArray objects and structured arrays just as it would on the corresponding ordinary lists. »
- Apply on Association objects operates on values only. »
- Apply[f][expr] is equivalent to Apply[f,expr].
- Parallelize[Apply[f,expr,levelspec]] computes Apply[f,expr,levelspec] in parallel on all subkernels. »
Examples
open all close allBasic Examples (6)
Replace the head of a list with f:
Apply[f, {a, b, c, d}]f@@{a, b, c, d}Sum a list by replacing the head with Plus:
Plus@@{1, 2, 3, 4}Apply gets rid of a level of lists:
f@@{{a, b}, {c}, d}Use the operator form of Apply:
Apply[f][{{a, b}, {c}, d}]Applying f to an Association keeps only values:
Apply[f, <|1 -> a, 2 -> b, 3 -> c|>]Applying a List to an Association is equivalent to Values:
Apply[List, <|1 -> a, 2 -> b, 3 -> c, 4 -> {d}|>]Values[<|1 -> a, 2 -> b, 3 -> c, 4 -> {d}|>]Scope (15)
Level Specifications (10)
Apply[f, {{a, b, c}, {d, e}}]f@@{{a, b, c}, {d, e}}Apply[f, {{a, b, c}, {d, e}}, {1}]Apply[f, {{a, b, c}, {d, e}}, {0, 1}]Apply down to level 2 (excluding level 0):
Apply[f, {{{{{a}}}}}, 2]Apply[f, {{{{{a}}}}}, {0, 2}]Apply at all levels, starting at level 1:
Apply[f, {{{{{a}}}}}, Infinity]Apply[f, {{{{{a}}}}}, {0, Infinity}]Apply[f, {{{{{a}}}}}, -1]Apply[f, {{{{{a}}}}}, -2]Apply[f, {{{{{a}}}}}, -3]Positive and negative levels can be mixed:
Apply[f, {{{{{a}}}}}, {2, -3}]Different heads at each level:
Apply[f, h0[h1[h2[h3[h4[a]]]]], {2, -3}]Apply also inside heads at the levels specified:
Apply[f, p[x][q[y]], {1}, Heads -> True]Types of Expressions (5)
Apply works with any head, not just List:
Apply[Plus, g[x, y, z]]Apply works on sparse arrays:
SparseArray[{1 -> 1, 2 -> 2, 10 -> 10}]Apply[List, %]Use Apply with structured arrays, such as SymmetrizedArray:
SymmetrizedArray[{{1, 2} -> 1, {1, 3} -> 2, {2, 3} -> 3}, {3, 3}, Antisymmetric[All]]f@@%Use Apply to apply a function to the rows of a structured array of type QuantityArray:
QuantityArray[{{1, 2}, {3, 4}, {5, 6}}, "Meters"]Apply[g, %, {1}]Apply f at the second level of an association; the association head is kept:
Apply[f, <|1 -> a, 2 -> b, 3 -> c, 4 -> {d, {e}}|>, {2}]Apply[f, <|1 -> a, 2 -> b, 3 -> c, 4 -> {d, {e}}|>, {0, 2}]Options (2)
Heads (2)
Apply inside heads as well as arguments:
Apply[f, p[x][q[y]], {1}, Heads -> True]Apply[f, p[x][q[y]], {1}]The option has no effect if including level zero:
Apply[f, p[x][q[y][r[z]]], {0, 1}, Heads -> True]Apply[f, p[x][q[y][r[z]]], {0, 1}, Heads -> False]Applications (4)
Display the factorization of an integer using superscripts:
FactorInteger[20!]CenterDot@@Apply[Superscript, %, {1}]Create a table from a list of range specifications:
Table[i ^ j, ##]&@@{{i, 3}, {j, 4}}Turn a function that takes several arguments into one that takes a list of arguments:
cplus[list_] := Plus@@listcplus[{a, b, c}]Find random co-prime integers:
Select[RandomInteger[10, {20, 2}], Apply[CoprimeQ]]Properties & Relations (5)
Total does effectively the same thing as applying Plus to a list:
Total[{a, b, c, d}]Plus@@{a, b, c, d}Using ## in a pure function has the same effect as using Apply:
Plus@@{1, 2, 3, 4}Plus[##]&[1, 2, 3, 4]Three ways to apply a function at level 1:
Apply[f, {{a, b}, {c, d}}, {1}]Using Map:
Apply[f, #]& /@ {{a, b}, {c, d}}Using MapApply:
f@@@{{a, b}, {c, d}}Ordinary function application takes the list as a single argument:
f@{a, b, c}Apply takes the elements of the list as separate arguments:
f@@{a, b, c}Compute Apply in parallel:
Parallelize[Apply[f, {{a, b, c}, {u, v, w}, {x, y}}, 1]]Tech Notes
Related Workflows
- Apply a Function to Cells in a Notebook
History
Introduced in 1988 (1.0) | Updated in 1999 (4.0) ▪ 2000 (4.1) ▪ 2002 (4.2) ▪ 2003 (5.0) ▪ 2014 (10.0)
Text
Wolfram Research (1988), Apply, Wolfram Language function, https://reference.wolfram.com/language/ref/Apply.html (updated 2014).
CMS
Wolfram Language. 1988. "Apply." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2014. https://reference.wolfram.com/language/ref/Apply.html.
APA
Wolfram Language. (1988). Apply. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Apply.html
BibTeX
@misc{reference.wolfram_2026_apply, author="Wolfram Research", title="{Apply}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/Apply.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_apply, organization={Wolfram Research}, title={Apply}, year={2014}, url={https://reference.wolfram.com/language/ref/Apply.html}, note=[Accessed: 13-June-2026]}