Home > Back-end >  Making three dimension numpy from two dimention list
Making three dimension numpy from two dimention list

Time:12-07

I want to make three dimension np (50, 917, 100) finally.

Now,I have variable sentence which has two dimention less than 917.

ex)

(812,100),(917,100),(250,100),(240,100),(560,100),,,,

So, I want to stack these variables to np variable and 0 padding where shorter..

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.

How can I do this ???

CodePudding user response:

appending would mean you stack those after your array of zeros. What you want to do instead is overwriting the respective parts in your initialized array:

for i, sentence in enumerate(all_sentences):
    res[i,:sentence.shape[0],:] = sentence
  • Related