我是一个新的numpy初学者。我想使用预训练的中文单词嵌入进行RNN训练。我想以纯文本的形式阅读嵌入并将它们转换为.npy文件。但我总是有错误。我使用了python3.4和numpy1.13。
嵌入以纯文本形式存储,如示例所示,由空格分隔:
中文字1 0.001334 0.001473 -0.001277 -0.001093 ......
中文字2 0.000417 -0.000250 -0.000319 -0.001105 ......
当我使用np.loadtxt时:
with open('/home/public/wordembedding/bigdata/test.txt',encoding='utf-8') as fr:
np.loadtxt(fr,dtype=str)
我收到了错误:
UnicodeEncodeError: 'latin-1' codec can't encode character '\uff0c' in position 0: ordinal not in range(256)
如果我尝试np.genfromtxt
with open('/home/public/wordembedding/bigdata/test.txt',encoding='utf-8') as fr:
np.genfromtxt(fr,delimiter=',',dtype=str)
我得到了
TypeError: Can't convert 'bytes' object to str implicitly
我google了很多,但仍未能解决问题,我浪费了很多时间。有没有人可以帮助我?非常感谢!!