# [Scipy-tickets] [SciPy] #1328: scipy.spatial.distance.sqeuclidean broken: Invalid results

SciPy Trac scipy-tickets@scipy....
Sun Jun 12 10:52:54 CDT 2011

```#1328: scipy.spatial.distance.sqeuclidean broken: Invalid results
------------------------------------------------------------------------------------+
Reporter:  stefan_r                                                                |       Owner:  peridot
Type:  defect                                                                  |      Status:  needs_review
Priority:  normal                                                                  |   Milestone:  0.10.0
Component:  scipy.spatial                                                           |     Version:  0.8.0
Keywords:  squared euclidean distance,distance,scipy.spatial.distance.sqeuclidean  |
------------------------------------------------------------------------------------+

Comment(by josefpktd):

I'm a bit confused about euclidean versus sdist versus pdist

sqeuclidean  looks wrongly  to using arrays

compare
https://github.com/scipy/scipy/blob/master/scipy/spatial/distance.py#L241
with
https://github.com/scipy/scipy/blob/master/scipy/spatial/distance.py#L215

these functions mix matrix operation *, .T and array operations, so there
might be some bugs for 2d data

{{{
>>> x = np.arange(10.).reshape(-1,2)
>>> y = 2.*x
>>> spatial.distance.euclidean(x, y)**2
1025.0
>>> spatial.distance.sqeuclidean(x, y)**2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python26\lib\site-packages\scipy\spatial\distance.py", line
265, in sqeuclidean
return ((u-v)*(u-v).T).sum()
ValueError: shape mismatch: objects cannot be broadcast to a single shape
>>> u,v = np.matrix(x), np.matrix(y)
>>> ((u-v)*(u-v).T).sum()
1025.0
}}}

--
Ticket URL: <http://projects.scipy.org/scipy/ticket/1328#comment:9>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.
```