The question, as originally asked, was absolutely too broad: the number of Python "calculations" that can produce a NaN
is essentially unbounded, limited only by the combined creativity of the Python programming community. Replacing "all the possible" with "the most common" just makes it subjective, too; arguably, it's still too broad, as there's a limitless number of possible answers depending on each answerer's definition of "most common".
That said, the question has a nice answer, which I'd hate to see lost. So what we should do is figure out what question the answer actually answers, and then edit the question to actually ask it.
The trick here, I believe, is to be specific. The help center suggests that a good SO question should be about "a specific programming problem". While the original question was written in the form of a (doomed) literature search looking for an exhaustive list of possible sources of NaN
s in Python, the specific programming problem behind it, which the answer correctly picks out, seems to be something like:
Where do NaNs come from?
I wrote some Python code (using numpy / scipy) to calculate a numerical value, but it returned NaN
instead. It seems that any further calculations I do with this NaN
value also return NaN
, but I'm sure that my original inputs didn't have any NaN
values in them.
What are these NaN
values, what kinds of operations produce them, and how can I find their source and fix it?
(This is just a quick draft; feel free to suggest improvements.)
IMO, rephrased like that, this is a valid and even a good question for SO: not so broad that it would be unanswerable, nor so narrow that it wouldn't be of use to other people. True, the lack of program code means we can't debug it ourselves and find the specific source of the OP's NaN
, but, as the existing answer demonstrates, that doesn't necessarily preclude us from providing a general answer that describes the typical sources of NaN
s and how to locate them.
Indeed, it could be argued that, for future visitors finding this question and answer on Google, such a general answer can actually be more useful than one that focuses on finding and fixing a particular bug in a particular piece of code.
Anyway, unless someone beats me to it (or unless this answer gets downvoted to oblivion), I'm going to edit the question later today to say something like my suggested wording above.
numpy/scipy
") The question doesn't have to "add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs." either.