Reputation: 25
import numpy
def euclideanClassification(punto1, punto2):
return (numpy.dot(punto2, punto1) - ((1.0/2.0) * numpy.dot(punto1, punto1)))
I'm trying to improve the performance of this function, but I don't know how.
This function is a variant of the Euclidean distance used in pattern recognition.
Upvotes: 1
Views: 116
Reputation: 4002
You could use Cython for that task.
[Cython] is a programming language based on Python, with extra syntax allowing for optional static type declarations. It aims to become a superset of the [Python] language which gives it high-level, object-oriented, functional, and dynamic programming. The source code gets translated into optimized C/C++ code and compiled as Python extension modules. This allows for both very fast program execution and tight integration with external C libraries, while keeping up the high programmer productivity for which the Python language is well known.
Upvotes: 0
Reputation: 18488
If I'm not mistaken, that formula should be equivalent to this:
numpy.dot(punto2 - 0.5 * punto1, punto1)
but if you write it like this you save three multiplications, so in theory it should be slightly faster.
Upvotes: 3