Skip to main content
added 143 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
mapAboveDiagonalmapAboveDiagonal1 = With[{dim = Dimensions[#2]}, 
 MapAt[#, #2, Join @@ Table[{i, j}, {i, dim[[1]]}, {j, i, dim[[2]]}]]] &

or

mapAboveDiagonal2 = MapAt[#, #2, 
  SparseArray[UpperTriangularize[
              ConstantArray[1, Dimensions[#2]]]]["NonzeroPositions"]]&;

mm = Array[m, {5, 5}];
Row[MatrixForm /@ {mm, mapAboveDiagonal[fmapAboveDiagonal1[f, mm]}]

enter image description here

mapAboveDiagonal = MapAt[#, #2, 
  SparseArray[UpperTriangularize[
              ConstantArray[1, Dimensions[#2]]]]["NonzeroPositions"]]&;

mm = Array[m, {5, 5}];
Row[MatrixForm /@ {mm, mapAboveDiagonal[f, mm]}]

enter image description here

mapAboveDiagonal1 = With[{dim = Dimensions[#2]}, 
 MapAt[#, #2, Join @@ Table[{i, j}, {i, dim[[1]]}, {j, i, dim[[2]]}]]] &

or

mapAboveDiagonal2 = MapAt[#, #2, 
  SparseArray[UpperTriangularize[
              ConstantArray[1, Dimensions[#2]]]]["NonzeroPositions"]]&;

mm = Array[m, {5, 5}];
Row[MatrixForm /@ {mm, mapAboveDiagonal1[f, mm]}]

enter image description here

Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

mapAboveDiagonal = MapAt[#, #2, 
  SparseArray[UpperTriangularize[
              ConstantArray[1, Dimensions[#2]]]]["NonzeroPositions"]]&;

mm = Array[m, {5, 5}];
Row[MatrixForm /@ {mm, mapAboveDiagonal[f, mm]}]

enter image description here