到目前为止,我得到的是:
Stats2003 = np.loadtxt('/DataFiles/2003.txt')
Stats2004 = np.loadtxt('/DataFiles/2004.txt')
Stats2005 = np.loadtxt('/DataFiles/2005.txt')
Stats2006 = np.loadtxt('/DataFiles/2006.txt')
Stats2007 = np.loadtxt('/DataFiles/2007.txt')
Stats2008 = np.loadtxt('/DataFiles/2008.txt')
Stats2009 = np.loadtxt('/DataFiles/2009.txt')
Stats2010 = np.loadtxt('/DataFiles/2010.txt')
Stats2011 = np.loadtxt('/DataFiles/2011.txt')
Stats2012 = np.loadtxt('/DataFiles/2012.txt')
Stats = Stats2003, Stats2004, Stats2004, Stats2005, Stats2006, Stats2007, Stats2008, Stats2009, Stats2010, Stats2011, Stats2012
我试图计算这些数组和其他数组之间的欧几里德距离,但我做起来有困难。在
通过计算距离,我可以得到如下输出:
^{pr2}$但是我想用一个循环来做这些计算。在
我用Prettytable将计算结果显示到一个表格中。在
谁能给我指出正确的方向吗?我之前没有找到任何有效的解决方案。在
要执行循环,您需要keep data out of your variable names。一个简单的解决办法是改用字典。这些循环在dict理解中是隐含的:
现在,通过
stats[2007]
访问特定年份的统计数据,并使用元组(例如dists[(2007, 20011)]
)访问距离。在看^{} 。在
根据文件:
所以你可以做如下操作:
如果您知道起始年份,并且您没有丢失任何年份的数据,那么很容易确定在距离矩阵的坐标
(m,n)
处比较哪两年。在相关问题 更多 >
编程相关推荐