[Numpy-discussion] meaning of accumulation/normalisation

Charles R Harris charlesr.harris@gmail....
Thu Apr 10 18:20:44 CDT 2008

On Thu, Apr 10, 2008 at 4:18 PM, wilson <wilson.t.thompson@gmail.com> 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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080410/4c7cdc7b/attachment.html 

More information about the Numpy-discussion mailing list