First page Back Continue Last page Overview Graphics

Combine Column Vectors

>>> S1 = np.array([3,7,8])

>>> S2 = np.array([1,11,1])

>>> S3 = np.array([-2,3,0])

>>> np.hstack((S1[:, np.newaxis],

S2[:, np.newaxis],

S3[:, np.newaxis]))

array([[ 3, 1, -2],

[ 7, 11, 3],

[ 8, 1, 0]])

Easier way to accomplish it:

>>> np.column_stack((S1, S2, S3))

array([[ 3, 1, -2],

[ 7, 11, 3],

[ 8, 1, 0]])

>>> np.row_stack((S1, S2, S3))

array([[ 3, 7, 8],

[ 1, 11, 1],

[-2, 3, 0]])