GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • WOLFRAM
  • Products
  • AI AccessUse with Mathematica and Wolfram|One
  • Finance Platform
  • Wolfram|Alpha Notebook Edition
  • Application Server
  • Enterprise Private Cloud
  • Wolfram Engine
  • Wolfram Player
  • Wolfram Cloud App
  • Wolfram Player App
  • Wolfram|Alpha Website
  • Wolfram|Alpha APIs
  • Wolfram AI Ecosystem

This view

  • Original page
  • New address

GeezerVison is showing reference.wolfram.com — MapAt—Wolfram Documentation

MapAt[f,expr,n]

applies f to the element at position n in expr. If n is negative, the position is counted from the end.

MapAt[f,expr,{i,j,…}]

applies f to the part of expr at position {i,j,…}.

MapAt[f,expr,{{i1,j1,…},{i2,j2,…},…}]

applies f to parts of expr at several positions.

MapAt[f,pos]

represents an operator form of MapAt that can be applied to an expression.

Details
Details and Options Details and Options
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

MapAt

MapAt[f,expr,n]

applies f to the element at position n in expr. If n is negative, the position is counted from the end.

MapAt[f,expr,{i,j,…}]

applies f to the part of expr at position {i,j,…}.

MapAt[f,expr,{{i1,j1,…},{i2,j2,…},…}]

applies f to parts of expr at several positions.

MapAt[f,pos]

represents an operator form of MapAt that can be applied to an expression.

Details

  • MapAt[f,expr,{i,j,…}] or MapAt[f,expr,{{i,j,…}}] applies f to the part expr[[i,j,…]].
  • The list of positions used by MapAt is in the same form as is returned by the function Position. »
  • MapAt works on Association objects, using the same specification for keys as in Part.
  • MapAt applies f repeatedly to a particular part if that part is mentioned more than once in the list of positions. »
  • MapAt[f,pos][expr] is equivalent to MapAt[f,expr,pos].

Examples

open all close all

Basic Examples  (5)

Map f onto the part at position 2:

Wolfram Language code: MapAt[f, {a, b, c, d}, 2]

Map f onto multiple parts:

Wolfram Language code: MapAt[f, {a, b, c, d}, {{1}, {4}}]

Map f onto a more deeply nested part:

Wolfram Language code: MapAt[f, {{a, b, c}, {d, e}}, {2, 1}]

Map f onto the second element of all top-level parts (the "second column"):

Wolfram Language code: MapAt[f, {{a, b, c}, {d, e}}, {All, 2}]

Use the operator form of MapAt:

Wolfram Language code: MapAt[f, 1][{a, b, c, d}]

Scope  (12)

Associations  (3)

Map f onto an association:

Wolfram Language code: MapAt[f, <|"a" -> 1, "b" -> 2, "c" -> 3, "d" -> 4, "e" -> 5|>, 3]

Use Key to specify position:

Wolfram Language code: MapAt[f, <|"a" -> 1, "b" -> 2, "c" -> 3, "d" -> 4|>, Key["b"]]

For string keys, Key is not needed:

Wolfram Language code: MapAt[f, <|"a" -> 1, "b" -> 2, "c" -> 3, "d" -> 4|>, "b"]

Use negative position in an association:

Wolfram Language code: MapAt[f, <|"a" -> 1, "b" -> 2, "c" -> 3, "d" -> 4|>, -3]

Part Specifications  (9)

A single element of the expression:

Wolfram Language code: MapAt[h, {{a, b, c}, {d, e}, f, g}, 2]

Negative numbers count from the end:

Wolfram Language code: MapAt[h, {{a, b, c}, {d, e}, f, g}, -3]

Map at a part at level 2:

Wolfram Language code: MapAt[h, {{a, b, c}, {d, e}, f, g}, {2, 1}]

Map at several elements:

Wolfram Language code: MapAt[h, {{a, b, c}, {d, e}, f, g}, {{2}, {1}}]

Map at several nested parts:

Wolfram Language code: MapAt[h, {{a, b, c}, {d, e}, f, g}, {{1, 1}, {2, 2}, {3}}]

Map using Span syntax:

Wolfram Language code: MapAt[f, {1, 2, 3, 4, 5, 6}, 3 ;; 4]

Map f at a more deeply nested part:

Wolfram Language code: MapAt[f, <|"a" -> 1, "b" -> {2, 3}, "c" -> 4, "d" -> 5|>, {"b", 1}]

Map f at several locations:

Wolfram Language code: MapAt[f, <|"a" -> 1, "b" -> 2, "c" -> 3, "d" -> 4|>, {{"a"}, {"b"}}]

Map f at several levels:

Wolfram Language code: 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:

Wolfram Language code: MapAt[f, a + b + c + d, 2]
Wolfram Language code: MapAt[f, x ^ 2 + y ^ 2, {{1, 1}, {2, 1}}]

Key and integer part specifications in associations are different:

Wolfram Language code: MapAt[f, <|3 -> "a", 2 -> "b", 1 -> "c"|>, {{1}, {Key[1]}}]

The function can be mapped onto the heads as well:

Wolfram Language code: MapAt[f, {a, b, c}, 0]

Map can be used on sparse arrays:

Wolfram Language code: SparseArray[{1 -> 1, 2 -> 2, 10 -> 10}]
Wolfram Language code: MapAt[f, %, {{1}, {5}, {10}}]

Applications  (4)

Reset an element in a matrix:

Wolfram Language code: MapAt[x&, {{a, b, c}, {d, e, f}}, {2, 1}]

Reverse the sign of an element in a matrix:

Wolfram Language code: MapAt[-#&, {{a, b, c}, {d, e, f}}, {2, 1}]

Enumerate cases with f mapped onto successive elements:

Wolfram Language code: Table[MapAt[f, {a, b, c, d}, i], {i, 4}]

Reverse the color of a cell at a random position at each step:

Wolfram Language code: 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:

Wolfram Language code: t = {x, x ^ 2, y, y ^ 2, z ^ 3};
Wolfram Language code: pos = Position[t, _ ^ _]
Wolfram Language code: MapAt[f, t, pos]

These are the subexpressions returned by Extract:

Wolfram Language code: Extract[t, pos]

MapAt applies f repeatedly if a part is mentioned repeatedly:

Wolfram Language code: MapAt[f, {a, b, c, d}, {{1}, {3}, {1}}]

Possible Issues  (1)

MapAt[f,expr,{}] does not map f because the list of positions is empty:

Wolfram Language code: MapAt[f, h[a, b], {}]

MapAt[f,expr,{{}}] maps f to position {}, which corresponds to the whole expression expr:

Wolfram Language code: MapAt[f, h[a, b], {{}}]

See Also

Map  ReplaceAt  MapIndexed  ReplacePart  Delete  FlattenAt

Function Repository: AssociationMapAt  MapAtKey  MapAtEvaluate

Tech Notes

    ▪
  • Applying Functions to Parts of Expressions

Related Guides

    ▪
  • Parts of Expressions
  • ▪
  • Applying Functions to Lists
  • ▪
  • Expressions
  • ▪
  • Functional Programming
  • ▪
  • Elements of Lists
  • ▪
  • Structural Operations on Expressions

Related Links

  • NKS|Online  (A New Kind of Science)

History

Introduced 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).

Text

Wolfram Research (1988), MapAt, Wolfram Language function, https://reference.wolfram.com/language/ref/MapAt.html (updated 2014).

CMS

Wolfram Language. 1988. "MapAt." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2014. https://reference.wolfram.com/language/ref/MapAt.html.

APA

Wolfram 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]}

Top
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.