Skip to content

Useful error for Hamming distance of different length arrays #4290

@anderspitman

Description

@anderspitman

When passed 2 arrays of differing length, scipy.spatial.distance.hamming raises:

AttributeError: 'bool' object has no attribute 'mean'

This is due to the way the hamming method calculates distance:

u = _validate_vector(u)
v = _validate_vector(v)
return (u != v).mean()

If the arrays have different lengths a single bool is returned by (u != v), and the mean method excepts. Would it be reasonable to detect length differences explicitly and raise a more meaningful exception?

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectA clear bug or issue that prevents SciPy from being installed or used as expectedscipy.spatial

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions