Skip to main content
2 votes

Canonical way to map a function to diagonal elements of a square matrix?

Just a variant: func[f_, mat_] := Fold[MapAt[f, #1, {#2, #2}] &, mat, Range[Length[mat[[1]]]]] For example: ...
ubpdqn's user avatar
  • 61.6k
2 votes

Canonical way to map a function to diagonal elements of a square matrix?

A = {{"a", 0, 0}, {0, E, 0}, {0, 0, E}}; With ReplaceAt (new in 13.1) we can easily add conditions: ...
eldo's user avatar
  • 74.4k
2 votes

How to efficiently Append a result of an operation on each element of a list to itself?

list = {{a, b, c}, {e, f, g}}; Using Comap (new in 14.0) ...
eldo's user avatar
  • 74.4k

Only top scored, non community-wiki answers of a minimum length are eligible