Python: how to check a variable is a meaningful numerical type
<p>In python, how can I check a variable is a numerical type and has a meaningful value? </p>

<p>Here I mean by 'numerical type' those like <code>int</code>, <code>float</code>, and <code>complex</code> with all different bit length, and by 'meaningful value' that it is not <code>nan</code> or any other special values that can not be used for further computation. </p>

<p>(I guess this is such a common issue and there must be a duplicate question, but I did not find one after a quick search. Please let me know if there is a duplicate.)</p>

<pre><code>&gt;&gt;&gt; from math import isnan
&gt;&gt;&gt; isnan(float('nan'))
True
&gt;&gt;&gt; isnan(1j.real)
False
&gt;&gt;&gt; isnan(1j.imag)
False
</code></pre>

<p>Integers can never be NaNs.</p>

python numpy math