Re: Selecting Rows Where All Columns Satisfy a Condition
- To: mathgroup at smc.vnet.net
- Subject: [mg82589] Re: Selecting Rows Where All Columns Satisfy a Condition
- From: Norbert Marxer <marxer at mec.li>
- Date: Fri, 26 Oct 2007 05:08:32 -0400 (EDT)
- References: <ffppu6$l6g$1@smc.vnet.net>
On 25 Okt., 12:08, Gregory Lypny <gregory.ly... at videotron.ca> 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 Hello You could use: Select[X, And @@ (#1 != -9 & ) /@ #1 & ] The following is a short test of the above code and shows that you get the same result: r := RandomInteger[{-10, -1}]; SeedRandom[1]; X = Table[{r, r, r, r}, {10}]; Select[X, #1[[1]] != -9 && #1[[2]] != -9 && #1[[3]] != -9 && #1[[4]] ! = -9 & ] == Select[X, And @@ (#1 != -9 & ) /@ #1 & ] Best Regards Norbert Marxer
- Follow-Ups:
- Re: Re: Selecting Rows Where All Columns Satisfy a Condition-Plot of Code speeds
- From: Syd Geraghty <sydgeraghty@mac.com>
- Re: Re: Selecting Rows Where All Columns Satisfy a Condition-Plot of Code speeds