mardi 26 juin 2018

error with random.sample: raise NotImplementedError(" >= and <= don't work with 0.") NotImplementedError: >= and <= don't work with 0

I have a problem with this code, I really dont understand why it cannot reach the second cycle of the most internal for:

def remove_random_links(A,E):
    rs = random.sample(A.edges, E)
    A.remove_edges_from(rs)

N = 30
L = [0,60,30,40,30,30,20,40]
rep = 15
d = []
g = []

for j in range(rep):
    R = nx.grid_graph(dim=[N,N])  
    _deg = []
    _gap = [] 
    for i in L:
        remove_random_links(R,i)
        A = nx.adj_matrix(R)
        L = nx.laplacian_matrix(R) 
        eigwd, eigv = LA.eigh(L.todense())
        eigw = np.sort(eigwd)
        eigw0 = eigw[0]
        eigw1 = eigw[1]
        eigw2 = eigw[2]
        eigw3 = eigw[3]
        gap = eigw2 - eigw1
        deg = eigw3 - eigw2
        _deg.append(deg)
        _gap.append(gap)
        print("meow")    
    d.append(_deg)
    g.append(_gap)
    print("M")

It goes on its first for cycle (the one in j) and then into its first for cycle in i, it completes it and then it is not able to do the second one because of this error with the function remove_random_links(), which gives me the following error:

File "/Users/Sofia/Desktop/delta.py", line 23, in remove_random_links(R,i)

File "/Users/Sofia/Desktop/delta.py", line 9, in remove_random_links rs = random.sample(A.edges, E)

File "/anaconda3/lib/python3.6/random.py", line 317, in sample if not 0 <= k <= n:

File "/anaconda3/lib/python3.6/site-packages/scipy/sparse/compressed.py", line 322, in ge "Comparing a sparse matrix with a scalar "

File "/anaconda3/lib/python3.6/site-packages/scipy/sparse/compressed.py", line 272, in _inequality raise NotImplementedError(" >= and <= don't work with 0.")

NotImplementedError: >= and <= don't work with 0.




Aucun commentaire:

Enregistrer un commentaire