Reputation: 503
I have this fairly simple problem. I want to calculate Euclidean distance with numpy with this code:
a= np.array([1,2,3])
b= np.array([2,3,4])
print((np.linalg.norm(a-b))**2)
This yields 2.9999999999999996
, However, the answer should be 3
. How do I achieve this?
Thanks
Upvotes: 0
Views: 355
Reputation: 80
You can use a round() function
a= np.array([1,2,3])
b= np.array([2,3,4])
print((np.linalg.norm(round(a-b))**2))
Upvotes: 0