|
import scipyimport scipy.spatial
尝试着用python来求解相互距离矩阵.
查了一下scipy.spatial才是需要import的.否则是AttributeError: 'module' object has no attribute 'spatial'的错误.
其中,aa1_pos.txt 是一个N*3的矩阵.
也扔上去.py_dis_matrix.py- import numpy as np
- import os
- import scipy.spatial as sps
- #import scipy as sps # wrong
- X=np.loadtxt('aa1_pos.txt')
- #print X
- Y=sps.distance.squareform(sps.distance.pdist(X,metric='euclidean'));
- #Y=sps.spatial.distance.squareform(sps.distance.pdist(X,metric='euclidean')); # wrong
- #print Y
- np.savetxt('./aa1_dis.txt',Y, '%8.3f',delimiter=' ',newline='\n')
复制代码
aa1_pos.txt
- 14.130 18.330 13.750
- 14.960 18.090 13.180
- 13.330 18.580 13.130
- 14.360 19.130 14.370
- 13.740 17.180 14.610
- 13.350 16.380 13.980
- 14.960 16.720 15.450
- 15.200 17.520 16.190
- 14.640 15.830 16.050
- 16.220 16.360 14.730
- 17.360 17.110 14.680
- 17.450 18.100 15.120
- 18.360 16.410 14.020
- 19.310 16.590 14.080
- 17.850 15.210 13.620
- 16.510 15.140 14.050
- 15.760 14.010 13.790
- 14.750 13.940 14.160
- 16.370 12.930 13.160
- 15.810 12.000 13.060
- 18.460 14.160 12.950
- 19.490 14.210 12.660
- 17.700 13.000 12.740
复制代码
|
|