Check the hstack and vstack . One or both of them pass arguments through atleast_nd . This is a perfectly acceptable way to modify an array.
Some other ways:
arr = np.array([1,2,3,4,5]).reshape(-1,1)
hstack and vstack convert their inputs with:
arrs = [atleast_1d(_m) for _m in tup] [atleast_2d(_m) for _m in tup]
test data:
a1=np.arange(2) a2=np.arange(10).reshape(2,5) a3=np.arange(8).reshape(2,4) np.hstack([a1.reshape(-1,1),a2,a3]) np.hstack([a1[:,None],a2,a3]) np.column_stack([a1,a2,a3])
result:
array([[0, 0, 1, 2, 3, 4, 0, 1, 2, 3], [1, 5, 6, 7, 8, 9, 4, 5, 6, 7]])
If you do not know in advance which arrays are 1d, then column_stack easiest to use. Others require a small function that checks the dimension before applying the change.
Numpy: use reshape or newaxis to add dimensions