Appending (hstack) a comformable array to a matrix returns error
<p>I am trying to <code>np.hstack</code> an array to a matrix. The array has <code>.shape</code> <code>(a,)</code>, the matrix has <code>.shape</code> <code>(a,b)</code>, with <code>a</code> and <code>b</code> integers. I get the error that dimensions do not match (<code>all the input arrays must have same number of dimensions</code>). What should I do to <code>hstack</code> these conformable objects?</p>

<p>Add an <em>extra axis</em> to the first array using <code>None</code> or <code>np.newaxis</code>:</p>

<pre><code>&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; a=  np.array([1,2,3])
&gt;&gt;&gt; a.shape
(3,)
&gt;&gt;&gt; b = np.array([[1], [2], [3]])
&gt;&gt;&gt; b.shape
(3, 1)
&gt;&gt;&gt; np.hstack((a[:, None], b))
array([[1, 1],
       [2, 2],
       [3, 3]])
</code></pre>

python append