Skip to content Skip to sidebar Skip to footer

Selecting A Column Vector From A Matrix In Python

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. x = np.array([[1,2],[3,4]]) x[:,1] >array([2, 4])

Solution 1:

Few options -

x[:,[1]]
x[:,None,1]
x[:,1,None]
x[:,1][:,None]
x[:,1].reshape(-1,1)
x[None,:,1].T

Post a Comment for "Selecting A Column Vector From A Matrix In Python"