Try numpy.hstack
with added axis to b -
a = np.array([[1,2,3],[4,5,6]])
b = np.array([1,7])
np.hstack([a,b[:,None]])
array([[1, 2, 3, 1],
[4, 5, 6, 7]])
Notes:
b[:,None]
adds an axis to turn b from 1D (2,)
to 2D (2,1)
array (its the same as b.reshape(-1,1)
)
np.hstack
is now able to horizontally stack (2,3)
and (2,1)
to give (2,4)
shaped array
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…