MathGroup Archive 2006

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

Search the Archive

Re: Selecting Many Things Rather Than Selecting One Thing FromMany

  • To: mathgroup at smc.vnet.net
  • Subject: [mg66201] Re: [mg66180] Selecting Many Things Rather Than Selecting One Thing FromMany
  • From: "David Annetts" <davidannetts at aapt.net.au>
  • Date: Thu, 4 May 2006 05:19:54 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Gregory, 

> I've discovered another use or need for the Select function, 
> which I suspect requires mapping of some sort.
> 
> In my previous posts, members of this MathGroup kindly showed 
> me how to apply Select to many columns of a matrix at once.  
> For example,
> 
> (Select[#1, #1 > K & ] & ) /@ Transpose[theMatrix]
> 
> will pull out all values greater than K, where K is a number 
> such as 100.
> 
> But suppose now that K is a list of numbers, such as K={34, 
> 876, 199}, and I simply want to extract or identify all of 
> the rows in the first column of theMatrix equal to any one of 
> those numbers.  How would I do that?  I started with
> 
> Select[theMatrix, #[[1]]==any element of list K]
> 
> and I imagine something similar could be applied to the 
> Position function.
> 
> Any hint would be much appreciated.

Firstly, isolate the first column using All (eg test[[All, 1]]).  Next, use
Position to find the rows that contain any of the elements in your target
vector like

	rownum = Position[test[[All, 1]], #]& /@ target//Flatten.

rownum has non-zero length you can then isolate the appropriate rows using
All again, for example,

	If[Length@rownum > 0, test[[#, All]]& /@ rownum]

Regards,

Dave.


  • Prev by Date: Re: Selecting Many Things Rather Than Selecting One Thing From Many
  • Next by Date: Re: Apparent accuracy error in least squares fit
  • Previous by thread: Re: Testing for squares
  • Next by thread: Re: Selecting Many Things Rather Than Selecting One Thi ng From Many