Converting List of Multidimensional Arrays to Single Multidimensional Array?
<p>Let Y be a list of 100 ndarrays, such that Y[i] is an ndarray of an image, its shape is 160x320x3.</p>

<p>I want X no be an ndarrays that contains all the images, I do as follows:</p>

<pre><code>x = [ y[i] for i in range(0,10) ]
</code></pre>

<p>But it produces a list of of 100 160X320X3 ndarrays. How can I modify it to get an ndarray of shape 100x160x320x3 ?</p>

<p>Calling <code>np.array</code> on <code>Y</code> (i.e <code>np.array(Y)</code>) should turn the list of ndarrays into one ndarray, with the size of the first axis corresponding to the length of the list.</p>

<p><em>Demo</em>:</p>

<pre><code>&gt;&gt;&gt; x = np.array([[1,2], [3,4]])
&gt;&gt;&gt; c = [x,x] # list of 2x2 arrays
&gt;&gt;&gt; c
[array([[1, 2],
       [3, 4]]), 
array([[1, 2],
       [3, 4]])]
&gt;&gt;&gt; np.array(c) # 2x2x2 array
array([[[1, 2],
        [3, 4]],

       [[1, 2],
        [3, 4]]])
</code></pre>

<p>Just call <code>np.array</code> on <code>Y</code>, or <code>x</code> if you only want a slice of <code>Y</code>.</p>

python numpy