total size of new array must be unchanged
<p>I have two arrays x1 and x2, both are 1*14 arrays i am trying to zip them up and then perform reshape.</p>

<p>The code is as below ;</p>

<pre><code>x1
</code></pre>

<p>Out[122]: array([1, 2, 3, 1, 5, 6, 5, 5, 6, 7, 8, 9, 7, 9])</p>

<pre><code>x2
</code></pre>

<p>Out[123]: array([1, 3, 2, 2, 8, 6, 7, 6, 7, 1, 2, 1, 1, 3])</p>

<pre><code>X = np.array(zip(x1, x2)).reshape(2, len(x1))
</code></pre>

<p>ValueErrorTraceback (most recent call last)
 in ()
----> 1 X = np.array(zip(x1, x2)).reshape(2, len(x1))</p>

<p>ValueError: total size of new array must be unchanged</p>

<p><code>np.array</code> isn't recognizing the generator created by <code>zip</code> as an iterable. It works fine if you force conversion to a list first:</p>

<pre><code>from array import array
import numpy as np
x1 = array('i', [1, 2, 3, 1, 5, 6, 5, 5, 6, 7, 8, 9, 7, 9])
x2 = array('i', [1, 3, 2, 2, 8, 6, 7, 6, 7, 1, 2, 1, 1, 3])
print(np.array(list(zip(x1, x2))).reshape(2, len(x1)))
</code></pre>

<p>gives</p>

<pre><code>[[1 1 2 3 3 2 1 2 5 8 6 6 5 7]
 [5 6 6 7 7 1 8 2 9 1 7 1 9 3]]
</code></pre>

python arrays numpy reshape