0

I am a noob in terms of Machine Learning. I am trying to program a K nearest neighbor algorithm, but I got an error for my array.

<ipython-input-206-78dc8182727c> in euclidean_distance(p1, p2)
      1 #Use pythagorean theorem to calculate distance between two points
      2 def euclidean_distance(p1,p2):
----> 3    return np.sqrt(np.sum((p1-p2))**2)

ValueError: operands could not be broadcast together with shapes (4,) (2,) 

Can someone help me in understanding and solving this problem? Thanks in advance.

  • _I am a noob in terms of Machine Learning._ No need to worry, this doesn't require any ML knowledge. What do you understand from that error message? – AMC Jun 10 '20 at 00:04
  • Does this answer your question? [python numpy ValueError: operands could not be broadcast together with shapes](https://stackoverflow.com/questions/24560298/python-numpy-valueerror-operands-could-not-be-broadcast-together-with-shapes) – AMC Jun 10 '20 at 00:10
  • Hi, sorry for the late reply, and thanks for the help. I don't completely understand arrays in numpy. However, p1 and p2 are parameters, so they should not be part of the problem. I already checked that thread, and I am not understanding it because the context is different, and I am not sure which part is relating to mine. Is there another solution that you are aware of? – Rene Egstolee Jun 10 '20 at 01:14

0 Answers0