concatenate arrays with mixed types
<p>consider the <code>np.array</code> <code>a</code></p>

<pre><code>a = np.concatenate(
    [np.arange(2).reshape(-1, 1),
     np.array([['a'], ['b']])],
    axis=1)
a

array([['0', 'a'],
       ['1', 'b']], 
      dtype='|S11')
</code></pre>

<p>How can I execute this concatenation such that the first column of <code>a</code> remains integers?</p>

<p>You can mix types in a numpy array by using a <code>numpy.object</code> as the <code>dtype</code>:</p>

<pre><code>&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; a = np.empty((2, 0), dtype=np.object)
&gt;&gt;&gt; a = np.append(a, np.arange(2).reshape(-1,1), axis=1)
&gt;&gt;&gt; a = np.append(a, np.array([['a'],['b']]), axis=1)
</code></pre>

<p>

<pre><code>&gt;&gt;&gt; a
array([[0, 'a'],
       [1, 'b']], dtype=object)
</code></pre>

<p>

<pre><code>&gt;&gt;&gt; type(a[0,0])
&lt;type 'int'&gt;
</code></pre>

<p>

<pre><code>&gt;&gt;&gt; type(a[0,1])
&lt;type 'str'&gt;
</code></pre>

python numpy