Inserting an array of arrays as the last column
<p>I have an array A:</p>

<pre><code>array([[1, 2, 3],
       [1, 1, 1],
       [2, 2, 2]])
</code></pre>

<p>and an array B:</p>

<pre><code>array([[1, 0],
       [1, 0],
       [0, 1]])
</code></pre>

<p>I want to make array B as the last column of array A, so I want the result array (let's call it C) to look like this:</p>

<pre><code>array([[1, 2, 3, [1, 0]],
       [1, 1, 1, [1, 0]],
       [2, 2, 2, [0, 1]]])
</code></pre>

<p>I tried: <code>np.insert(a,-1,b,axis=1)</code> , but this gave me an error:</p>

<pre><code>ValueError: could not broadcast input array from shape (2,3) into shape (3,3)
</code></pre>

<pre><code>print zip(*zip(*a)+[b.tolist(),])
</code></pre>

<p>although it wont be a numpy array afterwards </p>

<pre><code>&gt;&gt;&gt; a
array([[1, 2, 3],
       [1, 1, 1],
       [2, 2, 2]])
&gt;&gt;&gt; b
array([[1, 0],
       [1, 0],
       [0, 1]])
&gt;&gt;&gt; zip(*zip(*a)+[b.tolist(),])
[(1, 2, 3, [1, 0]), (1, 1, 1, [1, 0]), (2, 2, 2, [0, 1])]
</code></pre>

python numpy