1 回答

TA貢獻(xiàn)1873條經(jīng)驗(yàn) 獲得超9個(gè)贊
如果您使用的是 numpy 數(shù)組,則可以通過這種方式對(duì)它們進(jìn)行零填充:
# create your data
n_sample = 5
X = [np.random.uniform(0,1, (n_sample,43,1024)),
np.random.uniform(0,1, (n_sample,37,1024)),
np.random.uniform(0,1, (n_sample,42,1024))]
# find max dim
max_dim = np.max([x.shape[1] for x in X])
print(max_dim)
X_pad = []
for x in X:
X_pad.append(np.pad(x, ((0,0),(max_dim-x.shape[1],0),(0,0)), mode='constant')) # pre padding
# X_pad.append(np.pad(x, ((0,0),(0,max_dim-x.shape[1],(0,0)), mode='constant')) # post padding
# check padded shape
print([x.shape for x in X_pad])
添加回答
舉報(bào)