Selecting a column vector from a matrix in Python
<p>I would like to index a column vector in a matrix in Python/numpy and have it returned as a column vector and not a 1D array.</p>

<pre><code>x = np.array([[1,2],[3,4]])
x[:,1]
&gt;array([2, 4])
</code></pre>

<p>Giving </p>

<p><code>np.transpose(x[:,1])</code></p>

<p>is not a solution. Following the <code>numpy.transpose</code> documentation, this will return a row vector (1-D array).</p>

<p>Few options -</p>

<pre><code>x[:,[1]]
x[:,None,1]
x[:,1,None]
x[:,1][:,None]
x[:,1].reshape(-1,1)
x[None,:,1].T
</code></pre>

python numpy matrix indexing