I am trying to calculate euclidean distance between two INDArrays (supposing that INDArray is alternative of numpy array). In python, I have achieved this as:
import numpy as np
from scipy.spatial.distance import cdist
arr1 = np.array(of some size)
arr2 = np.array(of some size)
ans = cdist(arr2 , arr1)
example:
arr1 = [[20.73 62.67 ] # each row is a vector. so arr1 has 3 2-Dimensional vectors
[93.47 13.83]
[50.01 16.60]]
arr2 = [[20.66 6.09] # arr2 has 2 2-Dimensional vectors
[51.79 85.14]]
ans = [[56.57 73.21 31.17] # distances of vectors of arr2 with arr1
[38.33 82.59 68.55]]
Please help me achieve this in java. I dont know much about java. So far, I have come to conclusion that Nd4J can do this. But I dont know how.
NOTE: calculating euclidean using for loops
is not required. Actually I am trying to see performance impacts of vectorization on euclidean distance calculation. I come to know that Nd4J supports SIMD and vectorization just like Numpy. For details