I have a few large arrays (100 times larger than in the example) and I need to re-arrange them. Basically using tests on b and c, I need to pick elements of a.
a = RandomReal[1, 10^7];
b = RandomReal[1, 10^7];
c = RandomReal[1, 10^7];
sel = MapThread[(Abs[#1] <= 0.1) ∧ (Abs[#2] > 0.9)&, {b, c}]; // AbsoluteTiming
{10.9262,Null}
d = Pick[a, sel]; // AbsoluteTiming
{0.584831,Null}
MapThread and Pick are the only ways to do this, as far as I found, I can't re-arrange the code any more.
The selection generation takes awhile, many times longer than on other platforms, is there a faster way to speed this up?
selis not a packed array becauseMapThreaddoesn't pack automatically for some reason. That makesMapThreadeven less appealing. – Sjoerd Smit Oct 26 '18 at 20:38Abs[c] >= 0.9and notAbs[c] > 0.9as OP requested. – Szabolcs Oct 26 '18 at 21:22True/Falsewith1/0is more easily done withBoole. It works on lists too. – Szabolcs Oct 26 '18 at 21:27Boole. – kglr Oct 26 '18 at 21:29UnitStepconstruction, speeding it up:With[{sel=UnitStep[.1-Abs[b]]+UnitStep[Abs[c]-0.9]}, Pick[a, sel,2]]. – Fred Simons Nov 06 '18 at 15:55Abs[c] > 0.9, notAbs[c] >= 0.9) of your suggestion. – kglr Nov 06 '18 at 21:46