1

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 ???

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you basic idea of res[i,:sentence.shape[0],:] could be work for me in this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.