def mask_zero_div_zero(x, y, result, copy=False):
if is_scalar(y):<EOL><INDENT>y = np.array(y)<EOL><DEDENT>zmask = y == <NUM_LIT:0><EOL>if zmask.any():<EOL><INDENT>shape = result.shape<EOL>nan_mask = (zmask & (x == <NUM_LIT:0>)).ravel()<EOL>neginf_mask = (zmask & (x < <NUM_LIT:0>)).ravel()<EOL>posinf_mask = (zmask & (x > <NUM_LIT:0>)).ravel()<EOL>if nan_mask.any() or neginf_mask.any() or posinf_mask.any():<EOL><INDENT>result = result.astype('<STR_LIT>', copy=copy).ravel()<EOL>np.putmask(result, nan_mask, np.nan)<EOL>np.putmask(result, posinf_mask, np.inf)<EOL>np.putmask(result, neginf_mask, -np.inf)<EOL>result = result.reshape(shape)<EOL><DEDENT><DEDENT>return result<EOL>
Set results of 0 / 0 or 0 // 0 to np.nan, regardless of the dtypes
of the numerator or the denominator.

Parameters
----------
x : ndarray
y : ndarray
result : ndarray
copy : bool (default False)
    Whether to always create a new array or try to fill in the existing
    array if possible.

Returns
-------
filled_result : ndarray

Examples
--------
>>> x = np.array([1, 0, -1], dtype=np.int64)
>>> y = 0       # int 0; numpy behavior is different with float
>>> result = x / y
>>> result      # raw numpy result does not fill division by zero
array([0, 0, 0])
>>> mask_zero_div_zero(x, y, result)
array([ inf,  nan, -inf])