Skip to content

MAINT: != -> not_equal in hamming distance implementation#4293

Merged
argriffing merged 3 commits intoscipy:masterfrom
argriffing:improve-hamming-error-message
Dec 18, 2014
Merged

MAINT: != -> not_equal in hamming distance implementation#4293
argriffing merged 3 commits intoscipy:masterfrom
argriffing:improve-hamming-error-message

Conversation

@argriffing
Copy link
Copy Markdown
Contributor

closes #4290

@argriffing
Copy link
Copy Markdown
Contributor Author

>>> import numpy as np
>>> from scipy.spatial.distance import hamming
>>> a = np.array([0, 1, 1, 0], dtype=bool)
>>> b = np.array([0, 1, 1], dtype=bool)
>>> hamming(a, b)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  [...] spatial/distance.py", line 369, in hamming
    return np.not_equal(u, v).mean()
ValueError: operands could not be broadcast together with shapes (4,) (3,) 
>>> hamming(b, b)
0.0
>>> hamming(b, np.logical_not(b))
1.0

@larsmans
Copy link
Copy Markdown
Contributor

Regression test in argriffing#3.

@argriffing
Copy link
Copy Markdown
Contributor Author

@larsmans Thanks, merged your exception type regression test into this PR.

argriffing added a commit that referenced this pull request Dec 18, 2014
MAINT: != -> not_equal in hamming distance implementation
@argriffing argriffing merged commit 243ca56 into scipy:master Dec 18, 2014
@argriffing
Copy link
Copy Markdown
Contributor Author

merged my own PR, yolo

@rgommers rgommers added defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.spatial labels Dec 18, 2014
@rgommers rgommers added this to the 0.16.0 milestone Dec 18, 2014
@argriffing argriffing deleted the improve-hamming-error-message branch December 18, 2014 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.spatial

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Useful error for Hamming distance of different length arrays

4 participants