目前我有一个程序,找到坐标使它们成为列表并对它们执行点积函数,我最近尝试添加一个循环,以便它运行程序x次执行操作所有的坐标,但我似乎无法让它运行所有数据并显示所有答案,这是我的代码,它是非常基本的,因为我是一个初学程序员:
#!/usr/bin/python
l=[]
with open("coordinate_test") as f:
line = f.next()
nat = int(line.split()[0])
print nat
f.next()# skip headers
for line in f:
if line.strip():
l.append(map(float,line.split()[1:])) # make all values floats
#print l[0][0]
a = 1
for a in range(0,nat):
import operator
import numpy as np
vector1 = (int(l[0][0]),int(l[0][1]),int(l[0][2]))
vector2 = (int(l[a][0]),int(l[a][1]),int(l[a][2]))
#print vector1
#print vector2
x = vector1
y = vector2
vector3 = list(np.array(x) - np.array(y))
#print vector3
dotProduct = reduce( operator.add, map( operator.mul, vector3, vector3))
print dotProduct
a += 1
print a