Selecting a column vector from a matrix in Python

后端 未结 1 815
借酒劲吻你
借酒劲吻你 2021-01-14 08:10

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条回答
  • 2021-01-14 08:42

    Few options -

    x[:,[1]]
    x[:,None,1]
    x[:,1,None]
    x[:,1][:,None]
    x[:,1].reshape(-1,1)
    x[None,:,1].T
    
    0 讨论(0)
提交回复
热议问题