Skip to main content
deleted 1 character in body
Source Link
E. Chan-López
  • 31.1k
  • 3
  • 29
  • 50
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 SparseMatrixSparseArray:

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}}

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}}

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 SparseArray:

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}}

added 278 characters in body
Source Link
E. Chan-López
  • 31.1k
  • 3
  • 29
  • 50
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}}

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}}

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}}

Source Link
E. Chan-López
  • 31.1k
  • 3
  • 29
  • 50

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}}