(x, weights)
Extract the weight values of all zeros in a sparse matrix.
Extract the weight values of all zeros in a sparse matrix.
Extract the weight values of all zeros in a sparse matrix .
def sparse_implicit_zero_weights(x, weights):
    """ Extract the weight values of all zeros in a sparse matrix. """
    if not sp.issparse(x):
        raise TypeError('The matrix provided was not sparse.')

    if weights.ndim == 1:
        # Match weights and x axis so `indices` will be set appropriately
        if x.shape[0] == weights.shape[0]:
            x = x.tocsc()
        elif x.shape[1] == weights.shape[0]:
            x = x.tocsr()
        n_items = np.prod(x.shape)
        zero_indices = np.setdiff1d(np.arange(n_items), x.indices, assume_unique=True)
        return weights[zero_indices]
    else:
        # Can easily be implemented using a coo_matrix
        raise NotImplementedError(
            'Computing zero weights on ndimensinal weight matrix is not implemented'
        )
def sparse_implicit_zero_weights ( x , weights ) : if not sp . issparse ( x ) : raise TypeError ( 'The matrix provided was not sparse.' ) if weights . ndim == 1 : # Match weights and x axis so `indices` will be set appropriately if x . shape [ 0 ] == weights . shape [ 0 ] : x = x . tocsc ( ) elif x . shape [ 1 ] == weights . shape [ 0 ] : x = x . tocsr ( ) n_items = np . prod ( x . shape ) zero_indices = np . setdiff1d ( np . arange ( n_items ) , x . indices , assume_unique = True ) return weights [ zero_indices ] else : # Can easily be implemented using a coo_matrix raise NotImplementedError ( 'Computing zero weights on ndimensinal weight matrix is not implemented' )