Suppose I have two arrays of data, which I want to divide:
n = 1000;
a = RandomInteger[{1, 9}, {n, n}];
b = RandomInteger[{1, 9}, {n, n}];
First @ AbsoluteTiming @ (a/b)
0.637064
But suppose that two thirds of the values are actually zero. I'd want the ones dividing by zero to just remain zero.
mask = RandomChoice[{0, 0, 1}, {n, n}];
c = mask a;
d = mask b;
First @ AbsoluteTiming @ Quiet[c/d /. Indeterminate -> 0]
8.568857
Now it has become very slow. How can we speed this up?
Edit: Thanks for all the answers guys. Below are some timings:

Unitize@din place ofAbs@Sign@d. – Mr.Wizard Oct 28 '14 at 08:590/0ought to be0- in any case,Indeterminate -> 0is specified in the question. The question leaves open what should happen to a result like1/0orComplexInfinity. One might want infinity, zero or a different result, such as a maximum value. The general answer here effectively takes the union of the masks, which is a plausible (even common) use-case. But I think one ought to be careful in stating which generalized problem it is a solution to. - +1 long before now. :) – Michael E2 Oct 28 '14 at 12:40Unitizeand vectorization :) …OK, I've added a bit explanation, just a bit though. – xzczd Nov 01 '14 at 03:29