numpy中hstack()与vstack()区别

一、numpy.hstack()函数

函数原型:numpy.hstack(tup)
其中tup是arrays序列,The arrays must have the same shape, except in the dimensioncorresponding to
axis (the first, by default).
等价于:np.concatenate(tup, axis=1)

numpy.hstack()类似于  行堆积  另起一行
程序实例:
 


>>> a = np.array((1,2,3))

>>> b = np.array((2,3,4))

>>> np.hstack((a,b))

array([1, 2, 3, 2, 3, 4])


>>> a = np.array([[1],[2],[3]])

>>> b = np.array([[2],[3],[4]])

>>> np.hstack((a,b))

array([[1, 2],

       [2, 3],

       [3, 4]])

二、numpy.vstack()函数

函数原型:numpy.vstack(tup)

等价于:np.concatenate(tup, axis=0) if tup contains arrays thatare at least 2-dimensional.

numpy.vstack()类似于  列堆积  另起一列

程序实例:


>>> a = np.array([1, 2, 3])

>>> b = np.array([2, 3, 4])

>>> np.vstack((a,b))

array([[1, 2, 3],

       [2, 3, 4]])


>>> a = np.array([[1], [2], [3]])

>>> b = np.array([[2], [3], [4]])

>>> np.vstack((a,b))

array([[1],

       [2],

       [3],

       [2],

       [3],

       [4]])

 

 

 

你可能感兴趣的:(数据科学分析)