我想(50, 917, 100)最終制作三維np 。
現在,我有sentence兩個維度小于 917 的變數。
前任)
(812,100),(917,100),(250,100),(240,100),(560,100),,,,
所以,我想將這些變數堆疊到 np 變數和 0 填充更短的地方。
res = np.zeros((50,917,100)) # Initialize the empty numpy
print(res.shape)
for sentence in all_sentences: # len(all_sentences) = 50
res.append(sentence) #but it is wrong.
我怎樣才能做到這一點 ???
uj5u.com熱心網友回復:
追加意味著您將它們堆疊在您的零陣列之后。您想要做的是覆寫初始化陣列中的相應部分:
for i, sentence in enumerate(all_sentences):
res[i,:sentence.shape[0],:] = sentence
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/376355.html
