infinity

Why is log(inf + inf j) equal to (inf + 0.785398 j), In C++/Python/NumPy?

Why is log(inf + inf j) equal to (inf + 0.785398 j), In C++/Python/NumPy? Question: I’ve been finding a strange behaviour of log functions in C++ and numpy about the behaviour of log function handling complex infinite numbers. Specifically, log(inf + inf * 1j) equals (inf + 0.785398j) when I expect it to be (inf …

Total answers: 4

Why does `np.sum([-np.Inf, +np.Inf])` warn about "invalid value encountered in reduce"

Why does `np.sum([-np.Inf, +np.Inf])` warn about "invalid value encountered in reduce" Question: python -c "import numpy as np; print(np.sum([-np.Inf, +np.Inf]))" gives numpycorefromnumeric.py:86: RuntimeWarning: invalid value encountered in reduce return ufunc.reduce(obj, axis, dtype, out, **passkwargs) nan I wonder why that is: There is no warning in python -c "import numpy as np; print(np.sum([-np.Inf, -np.Inf]))" nor in …

Total answers: 2

Minus infinity in Python as a result of for loop?

Minus infinity in Python as a result of for loop? Question: I am trying to calculate valocity in Python with for loop. But when I run my code, I get "-inf" as a result for every row. This is my code: Vx = 0 for i in range(1, len(x_axis.timestamp)): Vx += Vx + (x_axis.diff_ts[i]) * …

Total answers: 1

How to make an integer larger than any other integer?

How to make an integer larger than any other integer? Question: Note: while the accepted answer achieves the result I wanted, and @ecatmur answer provides a more comprehensive option, I feel it’s very important to emphasize that my use case is a bad idea in the first place. This is explained very well in @Jason …

Total answers: 7

Testing for positive infinity, or negative infinity, individually in Python

Testing for positive infinity, or negative infinity, individually in Python Question: math.isinf() tests for positive or negative infinity lumped together. What’s the pythonic way to test for them distinctly? Ways to test for positive infinity: x == float(‘+inf’) math.isinf(x) and x > 0 Ways to test for negative infinity: x == float(‘-inf’) math.isinf(x) and x …

Total answers: 3

Replace -inf with zero value

Replace -inf with zero value Question: I have an array: x = numpy.array([-inf, -inf, 37.49668579]) Is there a way to change the -inf values to just 0? Asked By: user1821176 || Source Answers: There is: from numpy import inf x[x == -inf] = 0 Answered By: pv. Use isneginf http://docs.scipy.org/doc/numpy/reference/generated/numpy.isneginf.html#numpy.isneginf x[numpy.isneginf(x)] = 0 Answered By: …

Total answers: 3

How can I represent an infinite number in Python?

How can I represent an infinite number in Python? Question: How can I represent an infinite number in python? No matter which number you enter in the program, no number should be greater than this representation of infinity. Asked By: ssierral || Source Answers: I don’t know exactly what you are doing, but float(“inf”) gives …

Total answers: 13

Python Infinity – Any caveats?

Python Infinity – Any caveats? Question: So Python has positive and negative infinity: float(“inf”), float(“-inf”) This just seems like the type of feature that has to have some caveat. Is there anything I should be aware of? Asked By: Casebash || Source Answers: So does C99. The IEEE 754 floating point representation used by all …

Total answers: 5

In what contexts do programming languages make real use of an Infinity value?

In what contexts do programming languages make real use of an Infinity value? Question: So in Ruby there is a trick to specify infinity: 1.0/0 => Infinity I believe in Python you can do something like this float(‘inf’) These are just examples though, I’m sure most languages have infinity in some capacity. When would you …

Total answers: 24