Re: Lists and rules
- To: mathgroup at smc.vnet.net
- Subject: [mg66518] Re: Lists and rules
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Wed, 17 May 2006 03:30:55 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <e4bj1m$1b9$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Thomas Schmelzer wrote: > Experts, > I would like to produce a decent piece of code for one of my projects. > I am constructing a list of sets > > S_1, S_2 and S_3 > > where S_j = { m , T[[1,m]] == j, m running from 1 to 100} > > T[[1,*]] is a row vector containing only 1, 2 and 3. > > I could setup a for loop and work with append. I have done that, but I > believe this approach is neither efficient nor elegant. Any hints for a > newbie? > > Best, > Thomas > > > Hi Thomas, You could use *Table* [1]. For instance Subscript[S, 2] = Table[{m, T[[1,m]] == 2}, {m, 100}] generates S_2 as an 100 by 2 matrix where the first column ranges from 1 to 100 and the second contains the boolean values True or False depending on whether the value of T[[1,m]] is equal to 2. HTH, Jean-Marc [1] http://documents.wolfram.com/mathematica/functions/Table