Re: Selecting Rows Where All Columns Satisfy a Condition
- To: mathgroup at smc.vnet.net
- Subject: [mg82627] Re: Selecting Rows Where All Columns Satisfy a Condition
- From: Ray Koopman <koopman at sfu.ca>
- Date: Fri, 26 Oct 2007 05:28:04 -0400 (EDT)
- References: <ffppu6$l6g$1@smc.vnet.net>
On Oct 25, 3:08 am, 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 Select[X, FreeQ[#,-9]&] is compact, easily understood, and about 50% faster than your code. X[[ SparseArray[Times@@(Transpose@X + 9)] /. SparseArray[_, _, _, p_] :> Flatten@p[[2,2]] ]] is long, arcane, and about 35 times faster.