The computation of a Euclidean distance between two complex numbers with scipy.spatial.distance.euclidean
works:
import numpy
import scipy.spatial.distance
z1 = numpy.complex(numpy.cos(0), numpy.sin(0))
z2 = numpy.complex(numpy.cos(3*numpy.pi/2), numpy.sin(3*numpy.pi/2))
print scipy.spatial.distance.euclidean(z1, z2)
gives:
1.4142135623730951
However the pairwise distance matrix or the distance between each pair of the two input arrays doesn't work:
A = numpy.random.uniform(size=(5,1)) + numpy.random.uniform(size=(5,1))*1j
print scipy.spatial.distance.pdist(A)
returns a warning and the distances between the real parts:
lib/python2.7/site-packages/scipy/spatial/distance.py:107: ComplexWarning: Casting complex values to real discards the imaginary part
X = X.astype(np.double)
array([ 0.78016544, 0.66201108, 0.8330932 , 0.54355982, 0.11815436,
0.05292776, 0.23660562, 0.17108212, 0.11845125, 0.28953338])
It's the same with scipy.spatial.distance.cdist(A,A)
.
Is it possible to compute the pairwise distance matrix or the distance between each pair of the two input arrays using cdist or pdist, without using a for loop and scipy.spatial.distance.euclidean
which is too slow for my problem?