Created
June 11, 2019 23:45
-
-
Save ashunigion/040cee5865dd6f3e480acf72afe4d019 to your computer and use it in GitHub Desktop.
Padding the smaller reviews and truncating the large reviews
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pad_features(reviews_ints, seq_length): | |
''' Return features of review_ints, where each review is padded with 0's | |
or truncated to the input seq_length. | |
''' | |
features = [] | |
## implement function | |
for review in reviews_ints: | |
if len(review)<seq_length: | |
features.append(list(np.zeros(seq_length-len(review)))+review) | |
elif len(review)>seq_length: | |
features.append(review[:seq_length]) | |
else: | |
features.append(review) | |
features = np.array(features) | |
return features |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment