Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correct type error when using distance functions #686

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pyclustering/utils/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ def euclidean_distance_numpy(object1, object2):
@return (double) Euclidean distance between two objects.

"""
object2 = numpy.array(object2)
if len(object1.shape) > 1 or len(object2.shape) > 1:
return numpy.sqrt(numpy.sum(numpy.square(object1 - object2), axis=1))
else:
Expand Down Expand Up @@ -367,6 +368,7 @@ def euclidean_distance_square_numpy(object1, object2):
@return (double) Square Euclidean distance between two objects.

"""
object2 = numpy.array(object2)
if len(object1.shape) > 1 or len(object2.shape) > 1:
return numpy.sum(numpy.square(object1 - object2), axis=1).T
else:
Expand Down Expand Up @@ -408,6 +410,7 @@ def manhattan_distance_numpy(object1, object2):
@return (double) Manhattan distance between two objects.

"""
object2 = numpy.array(object2)
if len(object1.shape) > 1 or len(object2.shape) > 1:
return numpy.sum(numpy.absolute(object1 - object2), axis=1).T
else:
Expand Down Expand Up @@ -451,6 +454,7 @@ def chebyshev_distance_numpy(object1, object2):
@return (double) Chebyshev distance between two objects.

"""
object2 = numpy.array(object2)
if len(object1.shape) > 1 or len(object2.shape) > 1:
return numpy.max(numpy.absolute(object1 - object2), axis=1).T
else:
Expand Down Expand Up @@ -492,6 +496,7 @@ def minkowski_distance_numpy(object1, object2, degree=2):
@return (double) Minkowski distance between two object.

"""
object2 = numpy.array(object2)
if len(object1.shape) > 1 or len(object2.shape) > 1:
return numpy.power(numpy.sum(numpy.power(object1 - object2, degree), axis=1), 1/degree)
else:
Expand Down