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>I would assume you're on Python 3, in which the result is an array with a <code>zip</code> object. </p>

<p>You should call <code>list</code> on the <em>zipped</em> items:</p>

<pre><code>X = np.array(list(zip(x1, x2))).reshape(2, len(x1))
#            ^^^^
print(X)
# [[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>

<p>In Python 2, <code>zip</code> returns a list and not an iterator as with Python 3, and your previous code would work fine.</p>

python arrays numpy reshape