Skip to content Skip to sidebar Skip to footer

How To Exclude Some Numbers From A List

import networkx as nx import numpy as np import random from networkx.utils import powerlaw_sequence W=powerlaw_sequence(100,exponent=2.5) random.choice(W) What if I want the nu

Solution 1:

I don't know numpy, so perhaps there is another possible solution, but the following should work:

W = [x for x in powerlaw_sequence(100,exponent=2.5) if x != 0]

However, this reduces the length of W by the number of elements that are filtered out because of the condition x != 0.


Solution 2:


Post a Comment for "How To Exclude Some Numbers From A List"