Re: Subsetting indexed variable?
- To: mathgroup at smc.vnet.net
- Subject: [mg36071] Re: Subsetting indexed variable?
- From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
- Date: Thu, 15 Aug 2002 02:36:23 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Below I slightly modify a problem Gareth Russell had. I modified it to avoid confusion on how to generalize the solution to a different example. ------ suppose we have: b[1,3] = 3; b[0,6] = 6; b[5678, 3] = 7; b[5678, 4] = 5; Then how can we get a list of what (b) can return when the first argument is (5678). In this example we want to get {7,5}. The solution is to use the following: In[5]:= posn=Position[DownValues[b], b[5678,_] ]; Extract[DownValues[b], {First[#],2}& /@ posn ] Out[6]= {7,5} -------- Let myself or the mathgroup know if you have trouble understanding {First[#],2}& /@ posn -------- The solution above works because the definitions for (b) are stored in DownValues[b]. You can see the definitions if you evaluate the following. In[7]:= DownValues[b] -------- Regards, Ted Ersek download Mathematica Tips & Tricks from: http://www.verbeia.com/mathematica/tips/Tricks.html