我有这样的 Python 代码,这段代码应该简单地打印给定相似词的数组,例如“日本”
import spacy
import numpy as np
# Load the larger pre-trained English model
nlp = spacy.load("en_core_web_md")
# Get the vector for "japan"
word_vec = nlp("japan").vector
# Reshape the word_vec array to have a second dimension of size 1
word_vec = np.reshape(word_vec, (1, -1))
# Find the 3 most similar words to "japan"
most_similar = nlp.vocab.vectors.most_similar(word_vec, n=3)
# Extract the words from the most_similar list
similar_words = [nlp.vocab.strings[similar[0]] for similar in most_similar]
print(similar_words)
TypeError: only size-1 arrays can be converted to Python scalars
我该如何解决?