New answers tagged

8

A little too long for a comment, and I have marked this as 'Community Wiki' (not an original contribution). In addtion, I think the Query method should not be 'buried' in a comment. Query Sjoerd Smit has posted a neat method for applying a function to a matrix column using Query. Query[All, {1 -> (#+1/137&),3->(2 Pi# + 42&)}]@myTable2//...


6

kglr's ReplacePart method is completely general, but I think in many situations writing the rules explicitly is easier and gives more readable code. So I would write: data = Array[f, {4, 4}]; ReplacePart[data, {{r_, 1} :> data[[r, 1]] + 137, {r_, 3} :> 2 π data[[r, 3]]}] {{137 + f[1, 1], f[1, 2], 2 π f[1, 3], f[1, 4]}, {137 + f[2, 1], f[2, 2], 2 π f[...


8

myTable = Array[Subscript[a, Row[{##}]] &, {5, 10}]; MatrixForm @ myTable functions = {foo, bar}; columns = {2, 5}; 1. Part assignment: myTable[[All, columns]] = {foo@#, bar@#2} & @@@ myTable[[All, columns]]; myTable // MatrixForm 2. MapAt myTable = Array[Subscript[a, Row[{##}]] &, {5, 10}]; myTable = Fold[MapAt[First@#2, #, {All, Last@#2}] &...


Top 50 recent answers are included