[Numpy-discussion] more speed?

andrew x swan archiver at db.geocrawler.com
Thu Feb 17 11:34:11 CST 2000

This message was sent from Geocrawler.com by "andrew x swan" <a.swan at anprod.csiro.au>
Be sure to reply to that address.

hi - i've only just started using python and
numpy... the program i wrote below runs much more
slowly than a fortran equivalent. ie. on a dataset
where the order of the matrix is (3325,3325),
python took this long:

362.25user 0.74system 6:09.78elapsed 98%CPU 

and fortran took this long:

2.68user 1.12system 0:03.89elapsed 97%CPU

is this because the element by element
calculations involved are contained in python for



from Numeric import *

def nrm(pedigree):

    n_animals = len(pedigree) + 1
    nrm = zeros((n_animals,n_animals),Float)

    for i in xrange(1,n_animals):
        isire = pedigree[i-1][1]
        idam = pedigree[i-1][2]
        nrm[i,i] = 1.0 + 0.5 * nrm[isire,idam]
        for j in xrange(i+1,n_animals):
            jsire = pedigree[j-1][1]
            jdam = pedigree[j-1][2]
            nrm[j,i] = 0.5 * (nrm[jsire,i] +
            nrm[i,j] = nrm[j,i]

    return nrm

if __name__ == '__main__':

    test_ped = [(1,0,0),(2,0,0),(3,1,0),(4,1,2),

    a = nrm(test_ped)
    print a

Geocrawler.com - The Knowledge Archive

More information about the Numpy-discussion mailing list