Concatenating column vectors using numpy arrays

后端 未结 2 580
孤独总比滥情好
孤独总比滥情好 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.

    0 讨论(0)
  • 2020-12-08 15:48

    I tried the following. Hope this is good enough for what you are doing ?

    >>> np.vstack((a,b,c))
    array([[ 0,  1],
           [ 2,  1],
           [-1, -1]])
    >>> np.vstack((a,b,c)).T
    array([[ 0,  2, -1],
           [ 1,  1, -1]])
    
    0 讨论(0)
提交回复
热议问题