| Author |
Comment/Response |
yehuda
|
01/21/13 00:30am
In Response To 'Re: How to Add Pairs of Numbers in a List' --------- Just for the sake of completeness, and since in Mathematica you can everything in more than one way
data={{1,6},{2,3},{4,5}};
Table[data[[i, 1]] + data[[i, 2]], {i, Length[data]}]
Map[Total, data]
Total /@ data (* this is a shorthand notation *)
Apply[Plus, data, {1}]
Plus @@@ data( * this is a shorthand notation *)
data /. {x_, y_} -> x + y
other thing to remember that ease of writing is not always more efficient
For large lists of pairs
Map is the fastest and ReplaceAll (/.) is the slowest with speedup factor of almost 13
yehuda
yehuda
URL: , |
|