Student Support Forum: 'How to Add Pairs of Numbers in a List' topicStudent Support Forum > General > Archives > "How to Add Pairs of Numbers in a List"

 < Previous Comment Help | Reply To Comment | Reply To Topic
 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: ,

 Subject (listing for 'How to Add Pairs of Numbers in a List') Author Date Posted How to Add Pairs of Numbers in a List Jen 01/20/13 4:41pm Re: How to Add Pairs of Numbers in a List Bill Simpson 01/20/13 8:06pm Re: Re: How to Add Pairs of Numbers in a List Jen 01/20/13 9:31pm Re: Re: How to Add Pairs of Numbers in a List yehuda 01/21/13 00:30am
 < Previous Comment Help | Reply To Comment | Reply To Topic