A = {{E, 0, 0}, {0, E, 0}, {0, 0, E}}; Using `SubsetMap`: SubsetMap[Log@# &, #, Diagonal@Array[{##} &, Dimensions@#]] &@A > `{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}` Another way, using `ArrayRules` and `SparseMatrix`: A = {{"a", 0, 0}, {0, E, 0}, {0, 0, E}}; (*@eldo's matrix*) Normal@SparseArray@(Most@ArrayRules[A] /. Rule[{i_, i_}, a_ /; NumericQ[a]] :> Rule[{i, i}, Log@a]) > `{{"a", 0, 0}, {0, 1, 0}, {0, 0, 1}}`