Skip to content

Hamming distance returns unexpected value for string comparisons #11991

@fabianegli

Description

@fabianegli

Problem statement and current scipy behavior

The scipy.spatial.distance.hamming distance metric returns 1.0 for unequal strings but returns the expected values if strings are converted to lists beforehand.

The following code shows the output generated by the current version of scipy. Note the difference between the distance which is expected to be 0.25 for the chosen strings.

from scipy.spatial import distance
>>> distance.hamming("same", "tame")
1.0
>>> distance.hamming(list("same"), list("tame"))
0.25

Desired behavior

from scipy.spatial import distance
>>> distance.hamming("same", "tame")
0.25

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions