MathGroup Archive 2007

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

Search the Archive

Re: Selecting Rows Where All Columns Satisfy a Condition

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82610] Re: Selecting Rows Where All Columns Satisfy a Condition
  • From: samuel.blake at maths.monash.edu.au
  • Date: Fri, 26 Oct 2007 05:19:19 -0400 (EDT)
  • References: <ffppu6$l6g$1@smc.vnet.net>

Gregory Lypny wrote:
> Hello everyone
>
> I've got an Nx4 numeric array called X.  I'd like to pull out all
> rows where -9 does not appear in any of the four columns.  I know I
> can this:
>
> Select[X, #[[1]] != -9 && #[[2]] != -9 && #[[3]] != -9 && #[[4]] !=
> -9 &]
>
> But is there a more elegant way that applies the not-equal-to
> condition to each column without having to repeat it?
>
> Regards,
>
> 	Gregory

You could use this:

In[80]:= n = RandomInteger[{-10, 10}, {10, 4}]

Out[80]= {{-9, 10, -2, 0}, {-1, 1, 3, 3}, {-7, -1, 0, 3}, {-5, 7,
  10, -10}, {-7, 9, -8, -4}, {2, 2, -6, -6}, {5, 4, 1, 4}, {-1, -2,
  7, -9}, {-8, -2, 6, 4}, {0, 6, -6, -9}}

In[81]:= Select[n, FreeQ[#, -9] &]

Out[81]= {{-1, 1, 3, 3}, {-7, -1, 0, 3}, {-5, 7, 10, -10}, {-7,
  9, -8, -4}, {2, 2, -6, -6}, {5, 4, 1, 4}, {-8, -2, 6, 4}}



  • Prev by Date: Re: remove whitespace
  • Next by Date: Re: binomial sum bug
  • Previous by thread: Re: Selecting Rows Where All Columns Satisfy a Condition
  • Next by thread: Re: Selecting Rows Where All Columns Satisfy a Condition