(m, n, density)
return sp.sparse.csr_matrix((data, (row, col)), shape=(m, n))
Construct base function for sprand, sprandn.
Construct base function for sprand, sprandn.
Construct base function for sprand sprandn .
def _rand_sparse(m, n, density):
    """Construct base function for sprand, sprandn."""
    nnz = max(min(int(m*n*density), m*n), 0)

    row = np.random.randint(low=0, high=m-1, size=nnz)
    col = np.random.randint(low=0, high=n-1, size=nnz)
    data = np.ones(nnz, dtype=float)

    # duplicate (i,j) entries will be summed together
    return sp.sparse.csr_matrix((data, (row, col)), shape=(m, n))
def _rand_sparse ( m , n , density ) : nnz = max ( min ( int ( m * n * density ) , m * n ) , 0 ) row = np . random . randint ( low = 0 , high = m - 1 , size = nnz ) col = np . random . randint ( low = 0 , high = n - 1 , size = nnz ) data = np . ones ( nnz , dtype = float ) # duplicate (i,j) entries will be summed together return sp . sparse . csr_matrix ( ( data , ( row , col ) ) , shape = ( m , n ) )