我有一个小剧本:
from numpy import *
import numpy as np
import scipy.spatial as spt
X= np.loadtxt('edm')
myfile = open('edm.txt','w')
V= spt.distance.pdist(X.T,'sqeuclidean')
P = spt.distance.squareform(V)
print P
myfile.write(P)
这个矩阵:
0 199.778354301
201.857546133 0
如果我运行我的程序;我在终端上得到这个(根据“打印”):
[[ 0. 80657.85977805]
[ 80657.85977805 0. ]]
但在我的输出文件中,我得到如下无效字符:
��������z°¶¡±Û@z°¶¡±Û@��������
你知道为什么吗? 谢谢
该文件包含矩阵中数字的二进制表示形式。你知道吗
您可以使用NumPy
savetxt
方法来保存数组,而不用担心编码问题。你知道吗在文件里
相关问题 更多 >
编程相关推荐