Why is the correlation coefficient of a constant function with function input is not defined?
The correlation coefficient between two random variables is a rigorously defined mathematical parameter. It is undefined when either of the random variables have zero variance. Therefore "NaN" is a very appropriate value to return in this case.

You are welcome to define it to be zero when one of the random variables is constant, if you find this more practical. But this does not agree with my mathematical intuition using limits. For example, if $X$ is $Uniform[-1,1]$, then the correlation coefficient between $X$ and $Y = c + \epsilon X$ is 1 for all $\epsilon &gt; 0$, -1 for all $\epsilon &lt; 0$. You can modify this example to get functions that get closer and closer to a constant function as $\epsilon$ goes to zero, while the correlation between X and its image is any number from the interval [-1,1].

I also like this explanation by David Epstein: the cosine of an angle between a non-zero and a zero vector is fundamentally undefined.