Re: Question about Thread & Total
- To: mathgroup at smc.vnet.net
- Subject: [mg129590] Re: Question about Thread & Total
- From: Bob Hanlon <hanlonr357 at gmail.com>
- Date: Sat, 26 Jan 2013 16:58:46 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-newout@smc.vnet.net
- Delivered-to: mathgroup-newsend@smc.vnet.net
- References: <20130126063755.C0AB568AF@smc.vnet.net>
Thread[Total[{{1}, {2, 3}}]] // Trace shows that there is an initial attempt to evaluate the Total before the Thread is used . You can quiet the evaluation Thread[Total[{{1}, {2, 3}}]] // Quiet {1, 5} If you use two distinct steps to implement the second method, you can see why the second method works without complaint. The different length lists are never used together. Thread[h[{{1}, {2, 3}}]] {h[{1}], h[{2, 3}]} % /. h -> Total {1, 5} However, Map is better than Thread for this specific case. Total /@ {{1}, {2, 3}} {1, 5} Bob Hanlon On Sat, Jan 26, 2013 at 1:37 AM, Themis Matsoukas <tmatsoukas at me.com> wrote: > I was wondering why the error message in the example below: > > Thread[Total[{{1}, {2, 3}}]] > > Total::tllen: Lists of unequal length in {{1},{2,3}} cannot be added. >> > > {1, 5} > > On the other hand, the construction below gives the same answer without complaints: > > Thread[h[{{1}, {2, 3}}]] /. h -> Total > > {1, 5} >
- References:
- Question about Thread & Total
- From: Themis Matsoukas <tmatsoukas@me.com>
- Question about Thread & Total