How to create a numpy dtype from other dtypes?
<p>I normally create numpy dtypes like this:  </p>

<pre><code>C = np.dtype([('a',int),('b',float)])
</code></pre>

<p>However in my code I also use the fields <code>a</code> and <code>b</code> individually elsewhere:  </p>

<pre><code>A = np.dtype([('a',int)])
B = np.dtype([('b',float)])
</code></pre>

<p>For maintainability I'd like to derive <code>C</code> from types <code>A</code> and <code>B</code> somehow like this:  </p>

<pre><code>C = np.dtype([A,B])    # this gives a TypeError
</code></pre>

<p>Is there a way in numpy to create complex dtypes by combining other dtypes?</p>

<p>According to <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.dtype.html" rel="nofollow">dtype documentation</a>, dtypes have an attribute <code>descr</code> which provides an "<em>Array-interface compliant full description of the data-type</em>". Therefore:  </p>

<pre><code>A = np.dtype([('a',int)])    # A.descr -&gt; [('a', '&lt;i4')]
B = np.dtype([('b',float)])  # B.descr -&gt; [('b', '&lt;f8')]
# then
C = np.dtype([A.descr[0], B.descr[0]])
</code></pre>

python numpy numpy-dtype