GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing reference.wolfram.com — MapAt—Wolfram Documentation Details
Examples
Basic Examples
Scope
Associations
Part Specifications
Generalizations & Extensions
Applications
Properties & Relations
Possible Issues
See Also
Tech Notes
Related Guides
Related Links
History
Cite this Page
MapAtDetails
Examplesopen all close allBasic Examples (5)Map f onto the part at position 2: MapAt[f, {a, b, c, d}, 2]Map f onto multiple parts: MapAt[f, {a, b, c, d}, {{1}, {4}}]Map f onto a more deeply nested part: MapAt[f, {{a, b, c}, {d, e}}, {2, 1}]Map f onto the second element of all top-level parts (the "second column"): MapAt[f, {{a, b, c}, {d, e}}, {All, 2}]Use the operator form of MapAt: MapAt[f, 1][{a, b, c, d}]Scope (12)Associations (3)Map f onto an association: MapAt[f, <|"a" -> 1, "b" -> 2, "c" -> 3, "d" -> 4, "e" -> 5|>, 3]Use Key to specify position: MapAt[f, <|"a" -> 1, "b" -> 2, "c" -> 3, "d" -> 4|>, Key["b"]]For string keys, Key is not needed: MapAt[f, <|"a" -> 1, "b" -> 2, "c" -> 3, "d" -> 4|>, "b"]Use negative position in an association: MapAt[f, <|"a" -> 1, "b" -> 2, "c" -> 3, "d" -> 4|>, -3]Part Specifications (9)A single element of the expression: MapAt[h, {{a, b, c}, {d, e}, f, g}, 2]Negative numbers count from the end: MapAt[h, {{a, b, c}, {d, e}, f, g}, -3]Map at a part at level 2: MapAt[h, {{a, b, c}, {d, e}, f, g}, {2, 1}]Map at several elements: MapAt[h, {{a, b, c}, {d, e}, f, g}, {{2}, {1}}]Map at several nested parts: MapAt[h, {{a, b, c}, {d, e}, f, g}, {{1, 1}, {2, 2}, {3}}]Map using Span syntax: MapAt[f, {1, 2, 3, 4, 5, 6}, 3 ;; 4]Map f at a more deeply nested part: MapAt[f, <|"a" -> 1, "b" -> {2, 3}, "c" -> 4, "d" -> 5|>, {"b", 1}]Map f at several locations: MapAt[f, <|"a" -> 1, "b" -> 2, "c" -> 3, "d" -> 4|>, {{"a"}, {"b"}}]Map f at several levels: MapAt[f, <|1 -> x ^ 2 + y ^ 2|>, {{Key[1], 1, 1}, {Key[1], 2, 1}}]Generalizations & Extensions (4)MapAt can be used on expressions with any head: MapAt[f, a + b + c + d, 2]MapAt[f, x ^ 2 + y ^ 2, {{1, 1}, {2, 1}}]Key and integer part specifications in associations are different: MapAt[f, <|3 -> "a", 2 -> "b", 1 -> "c"|>, {{1}, {Key[1]}}]The function can be mapped onto the heads as well: MapAt[f, {a, b, c}, 0]Map can be used on sparse arrays: SparseArray[{1 -> 1, 2 -> 2, 10 -> 10}]MapAt[f, %, {{1}, {5}, {10}}]Applications (4)Reset an element in a matrix: MapAt[x&, {{a, b, c}, {d, e, f}}, {2, 1}]Reverse the sign of an element in a matrix: MapAt[-#&, {{a, b, c}, {d, e, f}}, {2, 1}]Enumerate cases with f mapped onto successive elements: Table[MapAt[f, {a, b, c, d}, i], {i, 4}]Reverse the color of a cell at a random position at each step: ArrayPlot[NestList[MapAt[1 - #&, #, RandomInteger[{1, 30}]]&, Table[0, {30}], 20], Mesh -> All]Properties & Relations (2)MapAt can use lists of parts returned by Position: t = {x, x ^ 2, y, y ^ 2, z ^ 3};pos = Position[t, _ ^ _]MapAt[f, t, pos]These are the subexpressions returned by Extract: Extract[t, pos]MapAt applies f repeatedly if a part is mentioned repeatedly: MapAt[f, {a, b, c, d}, {{1}, {3}, {1}}]See AlsoMap ReplaceAt MapIndexed ReplacePart Delete FlattenAt Function Repository: AssociationMapAt MapAtKey MapAtEvaluate Tech NotesRelated LinksHistoryIntroduced in 1988 (1.0) | Updated in 2014 (10.0)
Wolfram Research (1988), MapAt, Wolfram Language function, https://reference.wolfram.com/language/ref/MapAt.html (updated 2014).
TextWolfram Research (1988), MapAt, Wolfram Language function, https://reference.wolfram.com/language/ref/MapAt.html (updated 2014). CMSWolfram Language. 1988. "MapAt." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2014. https://reference.wolfram.com/language/ref/MapAt.html. APAWolfram Language. (1988). MapAt. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MapAt.html BibTeX@misc{reference.wolfram_2026_mapat, author="Wolfram Research", title="{MapAt}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/MapAt.html}", note=[Accessed: 12-November-2026]} BibLaTeX@online{reference.wolfram_2026_mapat, organization={Wolfram Research}, title={MapAt}, year={2014}, url={https://reference.wolfram.com/language/ref/MapAt.html}, note=[Accessed: 12-November-2026]} |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |