check type within numpy array
<p>I have different types of data. most of them are <code>int</code> and sometimes <code>float</code>. The <code>int</code> is different in size so 8/ 16/ 32 bits are the sizes.<br>
For this situation I'm creating a numerical type converter. therefore i check the type by using <code>isinstence()</code>. This because I have read that <code>isinstance()</code> is less worse than <code>type()</code>.</p>

<p>The point is that a lot of data i get is numpy arrays. I use spyder as IDE and then i see by the variables also a type. but when i type <code>isinstance(var,'type i read')</code> i get <code>False</code>.  </p>

<p>I did some checks:</p>

<pre><code>a = 2.17 
b = 3 
c = np.array(np.random.rand(2, 8))
d = np.array([1])
</code></pre>

<p>for there <code>isinstance(var,type)</code> i get:</p>

<pre><code>isinstance(a, float)
True
isinstance(b, int)
True
isinstance(c, float)  # or isinstance(c, np.float64)
False
isinstance(d, int)  # or isinstance(c, np.int32)
False
</code></pre>

<p><code>c</code> and <code>d</code> are True when i ask</p>

<pre><code>isinstance(c, np.ndarray)
True
isinstance(d, np.ndarray)
True
</code></pre>

<p>i can check with step in the <code>ndarray</code> by </p>

<pre><code>isinstance(c[i][j], np.float64)
True
isinstance(d[i], np.int32)
True
</code></pre>

<p>but this means that for every dimension i have to add a new index otherwise it is <code>False</code> again.
I can check there type with <code>dtype</code> like <code>c.dtype == 'float64'</code>...</p>

<p>Oke so for what i have find and tried...
My questions are basicly:</p>

<ul>
<li>how is the <code>var.dtype</code> method compared to <code>isinstance()</code> and <code>type()</code> (worst/ better etc)? </li>
<li>if <code>var.dtype</code> is even worse as <code>isinstance()</code> is there some method in the <code>isinstance()</code> without all the manual indexing? (autoindexing etc)? </li>
</ul>