[Date Index] [Thread Index] [Author Index]
Re: Selecting Rows Where All Columns Satisfy a Condition
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, #[] != -9 && #[] != -9 && #[] != -9 && #[] != > -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.