Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a certain depth before python see's a number a zero?

Tags:

python

Long story short, I'm creating a graph using networkx and the lower the weights between nodes(edges) the better.

My problem is pagerank doesn't like getting a weight of zero and gives me an error. So I was thinking is there a number that is essentially zero in python but not exactly zero. Something like 0.0000000000001?

or if my approach is really horrible(which I suspect it might) is there another way to deal with this? Pagerank recussivily gets a score and then normalizes it against the entire dataset so scores tend to be very low as dataset gets larger(think 1/billion nodes).

like image 705
Lostsoul Avatar asked Jul 11 '26 05:07

Lostsoul


2 Answers

>>> 1e-324
0.0
>>> 1e-323
9.8813129168249309e-324

Some interesting tests

>>> 1e-307 < sys.float_info.min
False
>>> 1e-307 > sys.float_info.min
True
>>> 1e-323 < sys.float_info.min
True
>>> 1e-323 + 1e-323
1.9762625833649862e-323
>>> 1e-324 + 1e-324
0.0

Update for @Kari's comment

Im curious why this is True

>>> 0.0 < 1e-323 < sys.float_info.min
True
like image 68
jdi Avatar answered Jul 13 '26 20:07

jdi


You can look at sys.float_info.min, the value of the minimum positive normalized float. On my system, this is 2.2250738585072014e-308.

like image 35
Ismail Badawi Avatar answered Jul 13 '26 18:07

Ismail Badawi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!