Maybe can you provide an example in order to give you some advice(s)?
Maybe you can reduce the number of loop(s) (only onbe one per time step typically), and you 'll be able to speedup your calculation for sure. An example, using append is very costly (dynamic memory allocation = a new matrix is created for each append call, to add a new row) and you can easily avoid it either by creating a matrix, or by adding a column a matrix; numpy is implicitly vertorized and it's fast if it's used correctly.
Share a bit more and the community will help you
(I've demonstrated to an intern that it's possible to reduce the duration from more than an hour to 40 seconds - 3 nested loops were used against no one finally; it depends on the topic).
here after a basic example from the numpy arrays/matrixes you get:
Maybe you can reduce the number of loop(s) (only onbe one per time step typically), and you 'll be able to speedup your calculation for sure. An example, using append is very costly (dynamic memory allocation = a new matrix is created for each append call, to add a new row) and you can easily avoid it either by creating a matrix, or by adding a column a matrix; numpy is implicitly vertorized and it's fast if it's used correctly.
Share a bit more and the community will help you
(I've demonstrated to an intern that it's possible to reduce the duration from more than an hour to 40 seconds - 3 nested loops were used against no one finally; it depends on the topic).
here after a basic example from the numpy arrays/matrixes you get:
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import numpy as np import time n = 1_000_000; # elt1 and elt2 are supposed to be 2 matrixes; the dimensions are (n,4) # column 1 = number of element #column 2/3/4 = X/Y/Z coordinates ## Matrixes build-up; the first column are the elements number elt1 = np.random.random((n,4)); elt2 = np.random.random((n,4)); i = np.arange(1,n+1, dtype = np.float); elt1[:,0] = i; elt2[:,0] = i; # now the dimension is supposed to be unknown t0 = time.time(); nr = np.shape(elt1)[0]; # nr = number of rows dist = np.sqrt( (elt2[:, 1] - elt1[:, 1])**2 + (elt2[:, 2] - elt1[:, 2])**2 + (elt2[:, 3] - elt1[:, 3])**2 ) t1 = time.time(); loc_minimum = np.where(dist == min(dist)); minimum = float(dist[loc_minimum]); print("The minimum is {} and located at the row number {}".format(minimum,int(loc_minimum[0]))); print("Duration : {}".format(t1-t0));Paul