Skip to main content
Source Link

Using b.gates.you.know.what's idea:

With[{f = Log}, 
     MapIndexed[Function[{x, id}, If[Equal @@ id, f[x], x]], A, {2}]]

Using an undocumented function:

res = A;
With[{f = Log}, LinearAlgebra`Private`SetMatrixDiagonal[res, f[Diagonal[res]]]];
res

Note that this function modifies matrices given to it, so you'll need to make a copy if you still need the starting matrix.

Post Made Community Wiki by J. M.'s missing motivation