On Thu, Apr 10, 2008 at 4:18 PM, wilson <[EMAIL PROTECTED]> wrote: > hi > i came across some image processing code in java and tried to > duplicate the operation on an ndarray.the array is supposed to contain > pixel values of a gryscale image generated by the program. however the > code does some accumulation operation as below to obtain a value > 'norm' > > ul=array(([....],[....]....,[...])) #containing float values > > def accumOperation(ul): > nr,nc=ul.shape > print "nr:",nr,"nc:",nc > val=0.0 > for r in range(nr): > for c in range(nc): > val+=ul[r][c]*ul[r][c] > return val > norm=accumOperation(ul) > newul=ul/norm > > the java doc mentions that by the above steps ul is normalised to unit > length (vector length)
Umm, not quite, it is missing a square root. You can get the same result by using the Frobenius norm NORM(X,'fro') is the Frobenius norm, sqrt(sum(diag(X'*X))) Which is matlab speak for sqrt(trace(dot(X.T, X))) or sqrt(inner(X.flat,X.flat)), but you can get it easier using norm(X,'fro'). I don't know why your code is missing a sqrt unless it drops out somewhere else. Basically, just treat an nxn array as a vector of length n**2. Chuck
_______________________________________________ Numpy-discussion mailing list [email protected] http://projects.scipy.org/mailman/listinfo/numpy-discussion
