Hello, I have the following code snippet
It currently uses for loops but it takes a bloody long time to run due to the numpy operations it has to perform for each iteration. How would I go about optimizing this code snippet?
I know best practices would have me target the most inner loop and employ some form of list comprehension, lambda function or something but I am unsure of implementation. Any help would be appreciated!
Code
import numpy as np
init = 0
end = 30
st = 1
end = 1024
dictVals = {'Name':[], 'data': []}
for i in range(0, 70):
for k in range(0, 1024):
for j in range(init, end):
dj=j - st + 1
if j != st:
if (np.abs(x[j][k]) > th) and (np.abs(x[j - 1][k]) > th):
if (np.dot(x[j][k],x[j - 1][k])) < 0:
dictVals ['data'][5][k][i]=dictVals ['data'][5][k][i] + 1
if j < (en - 1):
if (np.abs(dx[dj+1]) > th) and (np.abs(dx[dj]) > th):
if (np.dot(dx[dj],dx[dj + 1])) < 0:
dictVals ['data'][6][k][i]=dictVals ['data'][6][k][i] + 1It currently uses for loops but it takes a bloody long time to run due to the numpy operations it has to perform for each iteration. How would I go about optimizing this code snippet?
I know best practices would have me target the most inner loop and employ some form of list comprehension, lambda function or something but I am unsure of implementation. Any help would be appreciated!



![[Image: qZ42qWp.jpg]](https://i.imgur.com/qZ42qWp.jpg)