Numarray newbie question

ChinStrap caneff at gmail.com
Tue Mar 29 18:56:50 CEST 2005


Oh well. I am downloading all the things to build it, but in the mean
time I just did:

        def get_y_mat(x_ind,y_ind):

            return self.y_min + y_ind*self.dy

        def get_x_mat(x_ind,y_ind):

            return self.x_min + x_ind*self.dx

        self.x_mat=fromfunction(get_x_mat,matshape)
        self.y_mat=fromfunction(get_y_mat,matshape)

        def fxy(x_ind,y_ind):
            x=self.x_min + x_ind*self.dx
            y=self.y_min + y_ind*self.dx
            return f(x,y)

        def vxy(x_ind,y_ind):
            x=self.x_min + x_ind*self.dx
            y=self.y_min + y_ind*self.dx
            return v(x,y)

        self.f_mat=fromfunction(fxy,matshape)
        self.v_mat=fromfunction(vxy,matshape)

As you can see I am just repeating calculations in fxy and vxy that I
have already done for x_mat and y_mat.  This is still faster than
saying:

self.f_mat = array([f(x,y) for x in x_mat for y in y_mat],matshape)

by a noticable amount.




More information about the Python-list mailing list