hello
while trying to write a function that processes some numpy arrays and
calculate euclidean distance ,i ended up with this code
(though i used numpy ,i believe my problem has more to do with python
coding style..so am posting it here)
....
# i am using these numpy.ndarrays to do the calculation
facespace # of shape(totalimgs ,imgpixels)
weights # of shape(totalimgs ,selectedfacesp aces)
input_wk # of shape(selectedf acespaces,)
distance # of shape(selectedf acespaces,) initally all 0.0 's
mindistance #of shape(selectedf acespaces,) initally all
0.0 's
....
....
#here is the calculations part
for image in range(numimgs):
distance = abs(input_wk - weights[image, :])
if image==0:
#copy from distance to mindistance
mindistance=dis tance.copy()
if sum(mindistance ) sum(distance):
imgindex=image
mindistance=dis tance.copy()
if max(mindistance ) 0.0:
#normalise mindistance
mindistance=min distance/(max(mindistanc e)+1)
dist=sum(mindis tance)
this gets me the euclidean distance value.I want to know if the way i
coded it can be improved,made more compact....if someone can give
suggestions it will be a great help .
thanks
D
while trying to write a function that processes some numpy arrays and
calculate euclidean distance ,i ended up with this code
(though i used numpy ,i believe my problem has more to do with python
coding style..so am posting it here)
....
# i am using these numpy.ndarrays to do the calculation
facespace # of shape(totalimgs ,imgpixels)
weights # of shape(totalimgs ,selectedfacesp aces)
input_wk # of shape(selectedf acespaces,)
distance # of shape(selectedf acespaces,) initally all 0.0 's
mindistance #of shape(selectedf acespaces,) initally all
0.0 's
....
....
#here is the calculations part
for image in range(numimgs):
distance = abs(input_wk - weights[image, :])
if image==0:
#copy from distance to mindistance
mindistance=dis tance.copy()
if sum(mindistance ) sum(distance):
imgindex=image
mindistance=dis tance.copy()
if max(mindistance ) 0.0:
#normalise mindistance
mindistance=min distance/(max(mindistanc e)+1)
dist=sum(mindis tance)
this gets me the euclidean distance value.I want to know if the way i
coded it can be improved,made more compact....if someone can give
suggestions it will be a great help .
thanks
D
Comment