MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Subsetting indexed variable?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg36060] Re: Subsetting indexed variable?
  • From: Oliver Ruebenkoenig <ruebenko at donne.imtek.uni-freiburg.de>
  • Date: Thu, 15 Aug 2002 02:36:11 -0400 (EDT)
  • Organization: Rechenzentrum der Universitaet Freiburg, Germany
  • References: <ajajgf$9to$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Tue, 13 Aug 2002, Gareth J. Russell wrote:

> Hi,
> 
> I cannot seem to work out how to extract a subset of information from an
> indexed variable (without generating a full list/matrix first).
> 
> For example, suppose I define:
> 
> b[1,3] = 3
> b[2,3] = 7
> b[2,4] = 5
> 
> And I then want to get the list of all DEFINED values of b[2,_], i.e., the
> result should be {7,5}

try DownValues[b]

which gives you:

{HoldPattern[b[1, 3]] :> 3, HoldPattern[b[2, 3]] :> 7, 
  HoldPattern[b[2, 4]] :> 5}

an approach using sparse matrices would be:

bLst = {{1, 3} -> 3, {2, 3} -> 7, {2, 4} -> 5};

Position[bLst, {2, _} -> _]

{{2}, {3}}

bLst[[#1]][[1]][[2]] & /@ Position[bLst, {2, _} -> _] 

{7, 5}

hope that helps

oliver

Oliver Ruebenkoenig, <ruebenko at imtek.de>
   Phone: ++49 +761 203 7293



  • Prev by Date: Re: Need faster way to combine arrays
  • Next by Date: HTMLSave-continue Q
  • Previous by thread: RE: Subsetting indexed variable?
  • Next by thread: Re: Subsetting indexed variable?