Tuple error (numpy)
<p>I padded my data using <code>np.pad(x,[(0,0)], mode='constant')</code> and got this error:</p>

<pre><code>ValueError: Unable to create correctly shaped tuple from [(0, 0).
</code></pre>

<p>My <code>x</code> has  shape (21, 4) and I want to pad it to get a shape of (22,4).</p>

<p>Does anyone know what is happening?</p>

<p>The rank of the first argument has to match the number of pairs in the second argument.</p>

<p>For example, observe that this gives the error that you see:</p>

<pre><code>&gt;&gt;&gt; x = np.ones((21, 4))
&gt;&gt;&gt; np.pad(x, [(0,0)], mode='constant')
Traceback (most recent call last):
  [...snip...]
ValueError: Unable to create correctly shaped tuple from [(0, 0)]
</code></pre>

<p>The problem is that <code>x</code> has rank 2 but the second argument has only one pair, not two.</p>

<p>However, if we supply a second argument with two pairs, this succeeds:</p>

<pre><code>&gt;&gt;&gt; x2 = np.pad(x, [(0,0), (0,0)], mode='constant')
</code></pre>

<p>To get the final dimension that you want, we have to pad the first dimension by 1.  One way to do that is:</p>

<pre><code>&gt;&gt;&gt; x2 = np.pad(x, [(0,1), (0,0)], mode='constant')
&gt;&gt;&gt; x2.shape
(22, 4)
</code></pre>

python numpy