Re: Selecting Rows Where All Columns Satisfy a Condition

• To: mathgroup at smc.vnet.net
• Subject: [mg82593] Re: Selecting Rows Where All Columns Satisfy a Condition
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Fri, 26 Oct 2007 05:10:35 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <ffppu6\$l6g\$1@smc.vnet.net>

```Gregory Lypny wrote:

> 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?

You could use *FreeQ* as in In[3].

In[1]:= X = RandomInteger[{-10, 10}, {10, 4}]

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

In[2]:= Select[X, #[[1]] != -9 && #[[2]] != -9 && #[[3]] != -9 && \
#[[4]] != -9 &]

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

In[3]:= Select[X, FreeQ[#, -9] &]

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

Regards,
--
Jean-Marc

```

• Prev by Date: Re: Re: (x|y) \[element] Integers in Reduce function
• Next by Date: The Wolfram 2,3 Turing Machine Research Prize - Announcement
• Previous by thread: Re: Selecting Rows Where All Columns Satisfy a Condition
• Next by thread: Re: Selecting Rows Where All Columns Satisfy a Condition