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>A suggested duplicate recommends making a recarray or structured array.</p>

<p><a href="http://stackoverflow.com/questions/11309739/store-different-datatypes-in-one-numpy-array">Store different datatypes in one NumPy array?</a></p>

<p>In this case:</p>

<pre><code>In [324]: a = np.rec.fromarrays((np.arange(2).reshape(-1,1), np.array([['a'],['b']])))
In [325]: a
Out[325]: 
rec.array([[(0, 'a')],
 [(1, 'b')]], 
          dtype=[('f0', '&lt;i4'), ('f1', '&lt;U1')])
In [326]: a['f0']
Out[326]: 
array([[0],
       [1]])
In [327]: a['f1']
Out[327]: 
array([['a'],
       ['b']], 
      dtype='&lt;U1')
</code></pre>

<p>(I have reopened this because I think both approaches need to acknowledged.  Plus the <code>object</code> answer was already given and accepted.)</p>

python numpy