1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| >>> a = np.arange(8).reshape(2,4) >>> b = np.arange(8,12)
>>> np.vstack((a, b)) array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]])
>>> np.row_stack((a,b)) array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]])
>>> np.concatenate([a, b], axis=0) Traceback (most recent call last): File "<pyshell#99>", line 1, in <module> np.concatenate([a, b], axis=0) ValueError: all the input arrays must have same number of dimensions
>>> np.concatenate([a, [b,b]], axis=0) array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [ 8, 9, 10, 11]])
>>> np.r_[a,[b,b]] array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [ 8, 9, 10, 11]])
|