How to remove the infinite number or assign the infinite number to 0?

I used the math.log function on a list containing 0, and the calculated list contained infinite numbers. I now need to add the lists, but because there are infinite numbers, I can’t sum them.

@565384351 You can do something like this where you change the 0 to 1 in the beginning rather than handling Infinity later on. Tweak the rounding precision based on your requirement.

2 Likes

In cases where the value can’t be tweaked in advance this should do it:

Math.Abs(a)== Math.Abs(Math.Log(0)) ? 0 : a;

I am on my phone so this may not directly work, but the idea of checking if the absolute value is equal to the absolute value of infinity would hold true.

@JacobSmall That was the 1st thing I tried but looked like Dynamo doesn’t like to work with infinity so had to come up with “ignore infinity from start” solution.

The 1st code block gives all false but the same statement starts working in an if statement.


Your code block fails in 2.3.1 but works just fine in Sandbox.

Yeah - older builds (ie: 2.3 - which is in it’s last year of functional support as 2019 rolls into obsolescence in the next 6 or 7 months) will likely fail, as the Dynamo team put in some major work to allow support for really big numbers (and I believe allowing use of infinity more reliably) somewhere around 2.8. Worth having both solutions as in the future you might not be able to preemptively resolve to prevent -∞ or ∞ from occurring.

1 Like