我有以下代码来绘制单词向量:
import numpy as np
import matplotlib.pyplot as plt
la = np.linalg
words = ['I', 'like', 'enjoy', 'deep', 'learning', 'NLP', 'flying', '.']
X = np.array([ [0,2,1,0,0,0,0,0],
[2,0,0,1,0,1,0,0],
[1,0,0,0,0,0,1,0],
[0,1,0,0,1,0,0,0],
[0,0,0,1,0,0,0,1],
[0,1,0,0,0,0,0,1],
[0,0,1,0,0,0,0,1],
[0,0,0,0,1,1,1,0]])
U, s, Vh = la.svd(X, full_matrices = False)
ax = plt.axes()
for i in range(len(words)):
plt.text(U[i,0],U[i,1],words[i])
ax.arrow(0,0,U[i,0],U[i,1],head_width=0.1, head_length=0.1, fc='lightblue', ec='black')
plt.xlim(-.8,.2)
plt.ylim(-.8,.8)
plt.grid()
plt.title(' Simple SVD word vectors in Python',fontsize=10)
plt.show()
plt.close()
这将从原点开始绘制箭头。但是,当我试图从其他点来绘制if时。你知道吗
ax.arrow(-0.8,-0.8,U[i,0],U[i,1],head_width=0.1, head_length=0.1, fc='lightblue', ec='black')
它不画箭头!请问有什么问题?你知道吗
谢谢你。你知道吗
使用^{} :
相关问题 更多 >
编程相关推荐