Numpy padding 4D units with all zeros
<p>I have a 4D numpy array, but each element is a variable size 3D volume. Essentially it is a numpy list of 3D volumes. So the numpy array has the shape...</p>

<pre><code>(Pdb) batch_x.shape
(3,)
</code></pre>

<p>And take element <code>i</code> in that list, and it looks like this...</p>

<pre><code>(Pdb) batch_x[i].shape
(7, 70, 66)
</code></pre>

<p>I'm trying to pad each 3D volume with zeros, with the following code...</p>

<pre><code>for i in range(batch_size):
    pdb.set_trace()
    batch_x[i] = np.lib.pad(batch_x[i], (n_input_z - int(batch_x[i][:,0,0].shape[0]),
                                                    n_input_x - int(batch_x[i][0,:,0].shape[0]),
                                                    n_input_y - int(batch_x[i][0,0,:].shape[0])),
                                    'constant', constant_values=(0,0,0))
    batch_y[i] = np.lib.pad(batch_y[i], (n_input_z - int(batch_y[i][:,0,0].shape[0]),
                                                    n_input_x - int(batch_y[i][0,:,0].shape[0]),
                                                    n_input_y - int(batch_y[i][0,0,:].shape[0])),
                                    'constant', constant_values=(0,0,0))
</code></pre>

<p>There error is as follow...</p>

<p><code>*** ValueError: Unable to create correctly shaped tuple from (3, 5, 9)</code></p>

<p>I'm trying to pad each 3D volume such that they all have the same shape -- <code>[10,75,75]</code>. Keep in mind, like I showed above, <code>batch_x[i].shape = (7,70,66)</code> So the error message is at least showing me that my dimensions should be correct.</p>

<p>For evidence, debugging...</p>

<pre><code>(Pdb) int(batch_x[i][:,0,0].shape[0])
7
(Pdb) n_input_z
10
(Pdb) (n_input_z - int(batch_x[i][:,0,0].shape[0]))
3
</code></pre>