Reputation: 605
I want to calculate euclidean distance between X and Y, where X is not static. So, X is define by combination of range.:
a= np.arange(0.2,0.41,0.1)
b= np.arange(2,8,1)
c= np.arange(40,61,5)
d= np.arange(40,61,5)
e= np.arange(0,11,5)
f= np.arange(25,71,5)
from itertools import product
X = list(product(a,b,c,d,e,f))
X = np.around(X,2)
from scipy.spatial.distance import euclidean
dis = []
for x in np.nditer(X):
d = euclidean(x,[0.2,2,40,40,0,25]) #Inset Y here
dis.append(d)
min(dis)
Since in this case, to test if everything was working as I wanted, I input Y which is one of possible value of X. I expected my minimum distance to be 0, however in this case, it was not so (~47).
Upvotes: 2
Views: 71
Reputation: 463
The problem is that you're iterating over every individual number in X, rather than just iterating over the rows. Just remove the call to np.nditer(X) and iterate over X directly
for x in np.nditer(X):
should just be
for x in X:
Upvotes: 2