Bind columns (from vectors) for numpy

17,355

Solution 1

You can use numpy.vstack():

>>> import numpy
>>> a = numpy.zeros(3)
>>> b = numpy.ones(3)
>>> numpy.vstack((a,b)).T
array([[ 0.,  1.],
       [ 0.,  1.],
       [ 0.,  1.]])

Solution 2

np.column_stack

see Numpy: Concatenating multidimensional and unidimensional arrays

>>> import numpy
>>> a = numpy.zeros(3)
>>> b = numpy.ones(3)
>>> numpy.column_stack((a,b))
array([[ 0.,  1.],
       [ 0.,  1.],
       [ 0.,  1.]])
Share:
17,355
Hanfei Sun
Author by

Hanfei Sun

Just another stackoverflow user cs.cmu.edu/~hanfeis

Updated on September 16, 2022

Comments

  • Hanfei Sun
    Hanfei Sun over 1 year

    The codes are like this:

    a = numpy.zeros(3)
    b = numpy.ones(3)
    bind_by_column((a,b))
    => [[0,1],[0,1],[0,1]]
    

    I checked this but don't find the answer

    Does anyone have ideas about this?