(x, weights=None, axis=None, dtype=None, keepdims=False)
return counts
Count the undefined elements in an array along given axis.

    Parameters
    ----------
    x : array_like
    weights : array_like, optional
        Weights to weight the nans with, before or after counting (depending
        on the weights shape).
    axis : int, optional
    dtype : dtype, optional
        The data type of the returned array.

    Returns
    -------
    Union[np.ndarray, float]
Count the undefined elements in an array along given axis.
Count the undefined elements in an array along given axis .
def countnans(x, weights=None, axis=None, dtype=None, keepdims=False):
    """
    Count the undefined elements in an array along given axis.

    Parameters
    ----------
    x : array_like
    weights : array_like, optional
        Weights to weight the nans with, before or after counting (depending
        on the weights shape).
    axis : int, optional
    dtype : dtype, optional
        The data type of the returned array.

    Returns
    -------
    Union[np.ndarray, float]

    """
    if not sp.issparse(x):
        x = np.asanyarray(x)
        is_nan = np.isnan(x)
        if weights is not None and weights.shape == x.shape:
            is_nan = is_nan * weights

        counts = is_nan.sum(axis=axis, dtype=dtype, keepdims=keepdims)
        if weights is not None and weights.shape != x.shape:
            counts = counts * weights
    else:
        assert axis in [None, 0, 1], 'Only axis 0 and 1 are currently supported'
        # To have consistent behaviour with dense matrices, raise error when
        # `axis=1` and the array is 1d (e.g. [[1 2 3]])
        if x.shape[0] == 1 and axis == 1:
            raise ValueError('Axis %d is out of bounds' % axis)

        arr = x if axis == 1 else x.T

        if weights is not None:
            weights = weights if axis == 1 else weights.T

        arr = arr.tocsr()
        counts = _count_nans_per_row_sparse(arr, weights, dtype=dtype)

        # We want a scalar value if `axis=None` or if the sparse matrix is
        # actually a vector (e.g. [[1 2 3]]), but has `ndim=2` due to scipy
        # implementation
        if axis is None or x.shape[0] == 1:
            counts = counts.sum(dtype=dtype)

    return counts
def countnans ( x , weights = None , axis = None , dtype = None , keepdims = False ) : if not sp . issparse ( x ) : x = np . asanyarray ( x ) is_nan = np . isnan ( x ) if weights is not None and weights . shape == x . shape : is_nan = is_nan * weights counts = is_nan . sum ( axis = axis , dtype = dtype , keepdims = keepdims ) if weights is not None and weights . shape != x . shape : counts = counts * weights else : assert axis in [ None , 0 , 1 ] , 'Only axis 0 and 1 are currently supported' # To have consistent behaviour with dense matrices, raise error when # `axis=1` and the array is 1d (e.g. [[1 2 3]]) if x . shape [ 0 ] == 1 and axis == 1 : raise ValueError ( 'Axis %d is out of bounds' % axis ) arr = x if axis == 1 else x . T if weights is not None : weights = weights if axis == 1 else weights . T arr = arr . tocsr ( ) counts = _count_nans_per_row_sparse ( arr , weights , dtype = dtype ) # We want a scalar value if `axis=None` or if the sparse matrix is # actually a vector (e.g. [[1 2 3]]), but has `ndim=2` due to scipy # implementation if axis is None or x . shape [ 0 ] == 1 : counts = counts . sum ( dtype = dtype ) return counts