Put a 1D array into a 2D array
<p>I have a 2D array <code>x</code> in which I want to copy the content of a 1D array <code>y</code> :</p>

<pre><code>import numpy as np
x = np.array([[1, 2], [4, 5], [3, 3]], np.int32)
y = np.array([1, 2, 3, 4, 5, 6])

x[:,:] = y   # i would like x to be [[1, 2], [3, 4], [5, 6]]
</code></pre>

<blockquote>
  <p>ValueError: could not broadcast input array from shape (6) into shape (3,2)    </p>
</blockquote>

<p>How to do this ?</p>

<p>You have to convert the <code>y</code> to an array with a shape like <code>x</code>:</p>

<pre><code>&gt;&gt;&gt; x = y.reshape(x.shape)
&gt;&gt;&gt; x
array([[1, 2],
       [3, 4],
       [5, 6]])
</code></pre>

<p>But note that the <code>y</code> should be reshape with <code>x</code>'s shape.</p>

python arrays numpy