Converting 2D Numpy array to a list of 1D columns
<p>What would be the best way of converting a 2D numpy array into a list of 1D columns?</p>

<p>For instance, for an array:</p>

<pre><code>array([[ 0,  5, 10],
       [ 1,  6, 11],
       [ 2,  7, 12],
       [ 3,  8, 13],
       [ 4,  9, 14]])
</code></pre>

<p>I would like to get:</p>

<pre><code>[array([0, 1, 2, 3, 4]), array([5, 6, 7, 8, 9]), array([10, 11, 12, 13, 14])]
</code></pre>

<p>This works:</p>

<pre><code>[a[:, i] for i in range(a.shape[1])]
</code></pre>

<p>but I was wondering if there is a better solution using pure Numpy functions?</p>

<p>Here is one way:</p>

<pre><code>In [20]: list(a.T)
Out[20]: [array([0, 1, 2, 3, 4]), array([5, 6, 7, 8, 9]), array([10, 11, 12, 13, 14])]
</code></pre>

<p>Here is another one:</p>

<pre><code>In [40]: [*map(np.ravel, np.hsplit(a, 3))]
Out[40]: [array([0, 1, 2, 3, 4]), array([5, 6, 7, 8, 9]), array([10, 11, 12, 13, 14])]
</code></pre>

python numpy