1. Consider the following traversal of a numpy.ndarray
for ii in xrange(0,(nxTes-2)):
if ( (xCom-dtaCri-xcTes[ii]) * (xCom-dtaCri-xcTes[ii+1]) ) <= 0.0:
nxL=ii
if ( (xCom+dtaCri-xcTes[ii]) * (xCom+dtaCri-xcTes[ii+1]) ) <= 0.0:
nxR=ii+1
2. xCom, dtaCri and xcTes are of type() numpy.float64, float and numpy.ndarray respectively
3. The full block above is repeated for nyTes and nzTes i.e. a total of three blocks are done in the main algorithm loop. The goal is to create a region of interest with window size dtaCri and center at comparison point xCom using positional data from xcTes
4. The above code is more or less a straight port from Matlab wherein the same block executes at somewhere around three to four times the speed.
5. Question: Is it possible to optimize the block above with respect to execution time and if so how?
6. So far I have tried some minor tweaks such as altering data types and using range() instead of xrange() from which I saw no noticeable changes in performance.
numpyis more like old MATLAB where you had to focus on whole-matrix operations. Can you write that in MATLAB without the iteration? (with masks and so on)?