colour.algebra.sdiv#
- colour.algebra.sdiv(a: ArrayLike, b: ArrayLike) NDArrayFloat [source]#
Divide given array \(b\) with array \(b\) while handling zero-division.
This definition avoids NaNs and +/- infs generation when array \(b\) is equal to zero. This behaviour can be controlled with the
colour.algebra.set_sdiv_mode()
definition or with thesdiv_mode()
context manager. The following modes are available:Numpy
: The current Numpy zero-division handling occurs.Ignore
: Zero-division occurs silently.Warning
: Zero-division occurs with a warning.Ignore Zero Conversion
: Zero-division occurs silently and NaNs or +/- infs values are converted to zeros. Seenumpy.nan_to_num()
definition for more details.Warning Zero Conversion
: Zero-division occurs with a warning and NaNs or +/- infs values are converted to zeros. Seenumpy.nan_to_num()
definition for more details.Ignore Limit Conversion
: Zero-division occurs silently and NaNs or +/- infs values are converted to zeros or the largest +/- finite floating point values representable by the division resultnumpy.dtype
. Seenumpy.nan_to_num()
definition for more details.Warning Limit Conversion
: Zero-division occurs with a warning and NaNs or +/- infs values are converted to zeros or the largest +/- finite floating point values representable by the division resultnumpy.dtype
.
- Parameters:
a (ArrayLike) – Numerator array \(a\).
b (ArrayLike) – Denominator array \(b\).
- Returns:
Array \(b\) safely divided by \(a\).
- Return type:
np.float
ornumpy.ndarray
Examples
>>> a = np.array([0, 1, 2]) >>> b = np.array([2, 1, 0]) >>> sdiv(a, b) array([ 0., 1., 0.]) >>> try: ... with sdiv_mode("Raise"): ... sdiv(a, b) ... except Exception as error: ... error FloatingPointError('divide by zero encountered in...divide') >>> with sdiv_mode("Ignore Zero Conversion"): ... sdiv(a, b) array([ 0., 1., 0.]) >>> with sdiv_mode("Warning Zero Conversion"): ... sdiv(a, b) array([ 0., 1., 0.]) >>> with sdiv_mode("Ignore Limit Conversion"): ... sdiv(a, b) array([ 0.00000000e+000, 1.00000000e+000, 1.79769313e+308]) >>> with sdiv_mode("Warning Limit Conversion"): ... sdiv(a, b) array([ 0.00000000e+000, 1.00000000e+000, 1.79769313e+308])