(x, axis=None)
return result
Check if any of the values in a matrix is nan.
Check if any of the values in a matrix is nan.
Check if any of the values in a matrix is nan .
def any_nan(x, axis=None):
    """ Check if any of the values in a matrix is nan. """
    if not sp.issparse(x):
        return np.isnan(x).any(axis=axis)

    if axis is None:
        return np.isnan(x.data).any()

    if axis == 0:
        x = x.tocsc()
    elif axis == 1:
        x = x.tocsr()

    ax = x.ndim - axis - 1
    result = np.zeros(x.shape[ax], dtype=bool)
    for i in range(x.shape[ax]):
        vals = x.data[x.indptr[i]:x.indptr[i + 1]]
        result[i] = np.isnan(vals).any()

    return result
def any_nan ( x , axis = None ) : if not sp . issparse ( x ) : return np . isnan ( x ) . any ( axis = axis ) if axis is None : return np . isnan ( x . data ) . any ( ) if axis == 0 : x = x . tocsc ( ) elif axis == 1 : x = x . tocsr ( ) ax = x . ndim - axis - 1 result = np . zeros ( x . shape [ ax ] , dtype = bool ) for i in range ( x . shape [ ax ] ) : vals = x . data [ x . indptr [ i ] : x . indptr [ i + 1 ] ] result [ i ] = np . isnan ( vals ) . any ( ) return result