MapIndexed

WMA link


MapIndexed[f, expr]

applies f to each part on the first level of expr, including the part positions in the call to f.

MapIndexed[f, expr, levelspec]

applies f to each level specified by levelspec of expr.

Include heads (index 0):

Map on levels 0 through 1 (outer expression gets index {}):

Get the positions of atoms in an expression (convert operations to List first
to disable Listable functions):

Replace the heads with their positions, too:

The positions are given in the same format as used by Extract.
Thus, mapping Extract on the indices given by MapIndexed re-constructs the original expression:

MapAt
MapThread