Edited at

Getting projection in python

More than 1 year has passed since last update.

a = []

a.append(map(int, raw_input().split()))
an = np.array(a).reshape(2,2)
p12 = an[1]-an[0]

n = input()
a = []
for i in range(n):
a.append(map(int, raw_input().split()))
for aa in a:
hn = np.array(aa).reshape(1,2)
p10 = hn[0]-an[0]
norm = np.linalg.norm(p12)**2
ret = np.dot(p10,p12)/norm
print(p10,p12,ret,norm)
print(an[0] + p12 * ret)


Refs.