
The best way to get good optimized code is to find it. Does this do what you want? https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.Rbf.h... For some advice here, first avoid loops in Python and instead stick to ufuncs and broadcasting. It looks like the matrix is symmetric with constant diagonals, so much of the work can possibly be avoided. Finally consider threading over blocks or different basis functions. To dial it up to 11 write low level c code to do exactly what you want, writing a custom ufunc or call it cython. On Mar 25, 2017 2:03 PM, "Florian Lindner" <mailinglists@xgm.de> wrote:
Hello,
I have this function:
def eval_BF(self, meshA, meshB): """ Evaluates single BF or list of BFs on the meshes. """ if type(self.basisfunction) is list: A = np.empty((len(meshA), len(meshB))) for i, row in enumerate(meshA): for j, col in enumerate(meshB): A[i, j] = self.basisfunction[j](row - col) else: mgrid = np.meshgrid(meshB, meshA) A = self.basisfunction( np.abs(mgrid[0] - mgrid[1]) ) return A
meshA and meshB are 1-dimensional numpy arrays. self.basisfunction is e.g.
def Gaussian(radius, shape): """ Gaussian Basis Function """ return np.exp( -np.power(shape*abs(radius), 2))
or a list of partial instantations of such functions (from functools.partial).
How can I optimize eval_BF? Esp. in the case of basisfunction being a list.
Thanks! Florian _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@python.org https://mail.python.org/mailman/listinfo/numpy-discussion