I want to understand a specific part of code which computes a distance matrix between two 2d. matrices.
the smarter and easiest way to do it is by using scipy like this code
import scipy
import scipy.spatial
D = scipy.spatial.distance.cdist(X_norm, X_norm)
but there is an alternative way which i have a problem with to understand. It is this one
Dalt = np.sqrt(((X_norm ** 2).sum(axis=1).reshape((1, len(X_norm))) \
+ (X_norm ** 2).sum(axis=1).reshape((len(X_norm), 1)) \
- 2 * numpy.dot(X_norm, X_norm.T)) + 1e-7)
print(((Dalt - D) ** 2).mean())
What I actually do not understand is the last part when he finally add this part
+ le-7)