[Numpy-discussion] Numpy performance vs Matlab.

Sturla Molden sturla@molden...
Fri Jan 9 09:46:43 CST 2009


> I simplified the code to focus only on "what I" need, rather to bother you
> with the full code.

def test():
    w = 3096
    h = 2048
    a = numpy.zeros((h,w), order='F')      #Normally loaded with real data
    b = numpy.zeros((h,w,3), order='F')

    w0 = slice(0,w-2)
    w1 = slice(1,w-1)
    w2 = slice(2,w)
    h0 = slice(0,h-2)
    h1 = slice(1,h-1)
    h2 = slice(2,h)

    p00, p10, p20 = [h0,w0], [h1,w0], [h2,w0]
    p01, p11, p21 = [h0,w1], [h1,w1], [h2,w1]
    p02, p12, p22 = [h0,w2], [h1,w2], [h2,w2]

    b[p11 + [1]] =  a[p11] + 1.23*a[p22]  \
                     - numpy.min([a[p11]-a[p00],
                                  a[p11]-a[p01],
                                  a[p11]-a[p02],
                                  a[p11]-a[p10],
                                  a[p11]-a[p12],
                                  a[p11]-a[p20],
                                  a[p11]-a[p21],
                                  a[p11]-a[p22]])  \
                   + 0.123*numpy.max([a[p11]-a[p00],
                                      a[p11]-a[p01],
                                      a[p11]-a[p02],
                                      a[p11]-a[p10],
                                      a[p11]-a[p12],
                                      a[p11]-a[p20],
                                      a[p11]-a[p21],
                                      a[p11]-a[p22]])


Does this work for you?





More information about the Numpy-discussion mailing list