Here is my code
def makeFeatureVec(words, model, num_features):
featureVec=np.zeros((num_features, ), dtype="float32")
nwords=0.
index2word_set=set(model.wv.index2word)
for word in words:
if word in index2word_set:
nwords=nwords + 1.
featureVec=np.add(featureVec,model[word])
featureVec=np.divide(featureVec,nwords)
return featureVec
def getAvgFeatureVecs(reviews, model, num_features):
counter = 0.
reviewFeatureVecs = np.zeros((len(reviews), num_features), dtype="float32")
for review in reviews:
if counter%1000. == 0.:
print "Review %d of %d" % (counter, len(reviews))
reviewFeatureVecs[counter] = makeFeatureVec(review, model, num_features) <== Line no 182
counter = counter + 1.
return reviewFeatureVecs
Runtime Error Message
Traceback (most recent call last):
File "/test_IMDB_W2V_RF.py", line 198, in <module>
trainDataVecs=getAvgFeatureVecs(clean_train_reviews, model, num_features)
File "/test_IMDB_W2V_RF.py", line 182, in getAvgFeatureVecs
reviewFeatureVecs[counter] = makeFeatureVec(review, model, num_features)
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
Process finished with exit code 1
Description :
Can anyone explain how to overcome the indexing error.