连接2个array,如果是1维数组,要用 np.hstack,2维数组,要用 np.vstack。
但可以统一用 np.concatenate(, axis=0)。
>>> import numpy as np
>>> a=np.random.randn(3)
>>> a
array([-0.38378444, 0.15366378, 2.08474109])
>>> b=np.random.randn(4)
>>> b
array([ 1.78760893, 1.62298696, -1.22179612, 2.24867109])
>>> c=np.hstack((a,b))
>>> c
array([-0.38378444, 0.15366378, 2.08474109, 1.78760893, 1.62298696,-1.22179612, 2.24867109])
>>> a2=np.random.randn(3,2)
>>> a2
array([[-1.70912726, 0.54240495],[ 1.80379085, -0.67951491],[ 1.32351499, -0.09974404]])
>>> b2=np.random.randn(4,2)
>>> b2
array([[-0.23912084, -2.00947315],[-0.06506839, 0.54382329],[ 0.92202691, 0.20655242],[-0.84203558, 1.49998182]])
>>> c2=np.vstack((a2,b2))
>>> c2
array([[-1.70912726, 0.54240495],[ 1.80379085, -0.67951491],[ 1.32351499, -0.09974404],[-0.23912084, -2.00947315],[-0.06506839, 0.54382329],[ 0.92202691, 0.20655242],[-0.84203558, 1.49998182]])
>>> d=np.concatenate((a,b),axis=0)
>>> d
array([-0.38378444, 0.15366378, 2.08474109, 1.78760893, 1.62298696,-1.22179612, 2.24867109])
>>> d2=np.concatenate((a2,b2),axis=0)
>>> d2
array([[-1.70912726, 0.54240495],[ 1.80379085, -0.67951491],[ 1.32351499, -0.09974404],[-0.23912084, -2.00947315],[-0.06506839, 0.54382329],[ 0.92202691, 0.20655242],[-0.84203558, 1.49998182]])
>>>