xpipe.tools.selector.safedivide

xpipe.tools.selector.safedivide(x, y, eps=1e-08)[source]

Calculates x / y for arrays, setting result to zero if x ~ 0 OR y ~ 0

Defined such that

5 / 5 \rightarrow 1

but

5 / 0 \rightarrow 0 and 0 / 5 \rightarrow 0 and 0 / 0 \rightarrow 0

Parameters
  • x (np.array)

  • y (np.array)

  • eps (float) – threshold for setting element to zero

Returns

x / y where (xabs > eps) and (yabs > eps), 0 elsewhere

Return type

np.array