import numpy as np
a = np.array([i for i in range(5)])
b = np.array([i for i in range(5, 10)])
print('a:', a)
print('b:', b)
c = np.stack([a,b], axis=0)
print(c)
d = np.stack([a,b], axis=1)
print(d)
e = np.stack([a,b], axis=-1)
print(e)
结果:
a: [0 1 2 3 4]
b: [5 6 7 8 9]
c: [[0 1 2 3 4] # axis=0
[5 6 7 8 9]]
d: [[0 5] # axis=1
[1 6]
[3 8]
[4 9]]
e: [[0 5] # axis=-1
[1 6]
[3 8]
[4 9]]