#NEWLINE# def _replace_nan( a , val ) : #NEWLINE# #INDENT# '\n        If `a` is of inexact type, make a copy of `a`, replace NaNs with\n        the `val` value, and return the copy together with a boolean mask\n        marking the locations where NaNs were present. If `a` is not of\n        inexact type, do nothing and return `a` together with a mask of None.\n\n        Note that scalars will end up as array scalars, which is important\n        for using the result as the value of the out argument in some\n        operations.\n\n        Parameters\n        ----------\n        a : array-like\n            Input array.\n        val : float\n            NaN values are set to val before doing the operation.\n\n        Returns\n        -------\n        y : ndarray\n            If `a` is of inexact type, return a copy of `a` with the NaNs\n            replaced by the fill value, otherwise return `a`.\n        mask: {bool, None}\n            If `a` is of inexact type, return a boolean mask marking locations of\n            NaNs, otherwise return None.\n\n        ' #NEWLINE# is_new = ( not isinstance ( a , np . ndarray ) ) #NEWLINE# if is_new : #NEWLINE# #INDENT# a = np . array ( a ) #NEWLINE# #UNINDENT# if ( not issubclass ( a . dtype . type , np . inexact ) ) : #NEWLINE# #INDENT# return ( a , None ) #NEWLINE# #UNINDENT# if ( not is_new ) : #NEWLINE# #INDENT# a = np . array ( is_new , subok = True ) #NEWLINE# #UNINDENT# mask = np . isnan ( a ) #NEWLINE# np . copyto ( a , val , where = mask ) #NEWLINE# return ( a , mask )