# ValueError：操作数无法与形状一起广播（11,384）（96，）（11,384）

##### 问题描述投票：-1回答：1
``````nlp = spacy.load('en_core_web_sm')

vecs1 = [] <br>
for qu1 in tqdm(list(train_df['question1'])):<br>
doc1 = nlp(qu1) <br>
mean_vec1 = np.zeros([len(doc1), 384])<br>
for word1 in doc1:<br>
vec1 = word1.vector<br>
try: <br>
idf = word2tfidf[str(word1)]<br>
except:<br>
idf = 0<br>
# compute final vec<br>
mean_vec1 += (vec1 * idf)<br>
mean_vec1 = mean_vec1.mean(axis=0)<br>
vecs1.append(mean_vec1)<br>
train_df['q1_feats_m'] = list(vecs1)
``````

（）最近的ValueError Traceback（最近一次调用） 18 idf = 0 19＃计算最终的vec ---> 20 mean_vec1 + =（vec1 * idf） 21 mean_vec1 = mean_vec1.mean（axis = 0） 22 vecs1.append（mean_vec1）

ValueError：操作数无法与形状一起广播（11,384）（96，）（11,384）

python numpy spacy
##### 1个回答
0

``````nlp = spacy.load('en_core_web_sm')

vecs1 = []
for qu1 in tqdm(list(train_df['question1'])):
doc1 = nlp(qu1)
mean_vec1 = np.zeros([len(doc1), 384])
for word1 in doc1:
vec1 = word1.vector
try:
idf = word2tfidf[str(word1)]
except:
idf = 0

# Debug Prints
print("idf Shape: %s" %idf.shape)
print("vec1 Shape: %s" %vec1.shape)
print("mean_vec1 Shape: %s" %mean_vec1.shape)

# compute final vec
mean_vec1 += (vec1 * idf)
mean_vec1 = mean_vec1.mean(axis=0)
vecs1.append(mean_vec1)
train_df['q1_feats_m'] = list(vecs1)
``````