Concatenating column vectors using numpy arrays

后端 未结 2 603
孤独总比滥情好
孤独总比滥情好 2020-12-08 15:34

I\'d like to concatenate \'column\' vectors using numpy arrays but because numpy sees all arrays as row vectors by default, np.hstack and np.concatenate

2条回答
  •  清歌不尽
    2020-12-08 15:47

    I believe numpy.column_stack should do what you want. Example:

    >>> a = np.array((0, 1))
    >>> b = np.array((2, 1))
    >>> c = np.array((-1, -1))
    >>> numpy.column_stack((a,b,c))
    array([[ 0,  2, -1],
           [ 1,  1, -1]])
    

    It is essentially equal to

    >>> numpy.vstack((a,b,c)).T
    

    though. As it says in the documentation.

提交回复
热议问题