(func, X)
Apply function row-wise to input matrix X.
    This will work for dense matrices (eg np.ndarray)
    as well as for CSR sparse matrices.
Apply function row-wise to input matrix X.
    This will work for dense matrices (eg np.ndarray)
    as well as for CSR sparse matrices.
Apply function row - wise to input matrix X . This will work for dense matrices ( eg np . ndarray ) as well as for CSR sparse matrices .
def apply_along_rows(func, X):
    """
    Apply function row-wise to input matrix X.
    This will work for dense matrices (eg np.ndarray)
    as well as for CSR sparse matrices.

    """
    if issparse(X):
        return np.array([
            func(X.getrow(i))
            for i in range(X.shape[0])
        ])
    else:
        # XXX might break vis-a-vis this issue merging: https://github.com/numpy/numpy/pull/8511
        # See discussion over issue with truncated string when using np.apply_along_axis here:
        #   https://github.com/numpy/numpy/issues/8352
        return np.ma.apply_along_axis(
            lambda x: func(x.reshape(1, -1)),
            axis=1,
            arr=X,
        )
def apply_along_rows ( func , X ) : if issparse ( X ) : return np . array ( [ func ( X . getrow ( i ) ) for i in range ( X . shape [ 0 ] ) ] ) else : # XXX might break vis-a-vis this issue merging: https://github.com/numpy/numpy/pull/8511 # See discussion over issue with truncated string when using np.apply_along_axis here: #   https://github.com/numpy/numpy/issues/8352 return np . ma . apply_along_axis ( lambda x : func ( x . reshape ( 1 , - 1 ) ) , axis = 1 , arr = X , )