N
nodrogbrown
hi
i am using python to do some image data calculations..I use the
following numpy.ndarrays ,(i have given their shapes and ranks)
weights=ndarray :shape(100,30),ndim=2 will have vals like
2458121847.49 (of type 'numpy.float64')
input_weight=ndarray :shape(30,),ndim=1 (similar to above but diff
vals)
distance =ndarray :shape(30,),ndim=1
mindistance==ndarray :shape(30,),ndim=1
now i am calculating the euclidian distance of 'input_weight' from
'weight'
since this is the cumulative diff i do this in this way
<code>
for image in range(100):
temp=0.0
for j in range(30):
distance[j]=abs(input_weight[j]-weights[image,j])
if(image==0):
#at the start copy from distance to mindistance
mindistance=distance.copy()
if (sum(mindistance) > sum(distance)):
imgindex=image # i use this later to access a list
mindistance=distance.copy()
# now normalise the mindistance
array
if (max(mindistance) > 0.0):
mindistance=mindistance/(max(mindistance))
dist=sum(mindistance)
<code>
this gives me the correct results but i am worried if this is a bit
unpythonish?
(been a java programmer for a long time..) i wd like to know if there
is a better way
gordon
i am using python to do some image data calculations..I use the
following numpy.ndarrays ,(i have given their shapes and ranks)
weights=ndarray :shape(100,30),ndim=2 will have vals like
2458121847.49 (of type 'numpy.float64')
input_weight=ndarray :shape(30,),ndim=1 (similar to above but diff
vals)
distance =ndarray :shape(30,),ndim=1
mindistance==ndarray :shape(30,),ndim=1
now i am calculating the euclidian distance of 'input_weight' from
'weight'
since this is the cumulative diff i do this in this way
<code>
for image in range(100):
temp=0.0
for j in range(30):
distance[j]=abs(input_weight[j]-weights[image,j])
if(image==0):
#at the start copy from distance to mindistance
mindistance=distance.copy()
if (sum(mindistance) > sum(distance)):
imgindex=image # i use this later to access a list
mindistance=distance.copy()
# now normalise the mindistance
array
if (max(mindistance) > 0.0):
mindistance=mindistance/(max(mindistance))
dist=sum(mindistance)
<code>
this gives me the correct results but i am worried if this is a bit
unpythonish?
(been a java programmer for a long time..) i wd like to know if there
is a better way
gordon