import numpy as np
a=np.asarray([1,2,3,4,5,6])
b=np.asarray([11,22,33])
c=np.asarray([44,55,66])
x1 = np.concatenate((a,a),axis=0) # 默认情况下,axis=0可以不写
x2 = np.concatenate((b,b),axis=0)
x3 = np.concatenate((c,c),axis=0)
print("x1:", x1)
print("x2:", x2)
print("x3:", x3)
obs_n = []
obs_n.append(x1)
obs_n.append(x2)
obs_n.append(x3)
print("np.array(obs_n).shape:", np.array(obs_n).shape)
print('obs_n:', obs_n)
obs_m = []
obs_m.append(x2)
obs_m.append(x2)
obs_m.append(x3)
# print(np.asarray(x1))
# print(np.asarray(x2))
# print(np.asarray(x3))
print("np.array(obs_m).shape:", np.array(obs_m).shape)
print('obs_m:', obs_m)
'''
x1: [1 2 3 4 5 6 1 2 3 4 5 6]
x2: [11 22 33 11 22 33]
x3: [44 55 66 44 55 66]
np.array(obs_n).shape: (3,)
obs_n:
[array([1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6]),
array([11, 22, 33, 11, 22, 33]),
array([44, 55, 66, 44, 55, 66])]
np.array(obs_m).shape: (3, 6)
obs_m:
[array([11, 22, 33, 11, 22, 33]),
array([11, 22, 33, 11, 22, 33]),
array([44, 55, 66, 44, 55, 66])]
'''
One-dimensional array of different length append
Guess you like
Origin blog.csdn.net/gz153016/article/details/114765942
Recommended
Ranking