I am new to python, I am writing a simple code in python it consist of for loops within that if loops. After am running this code its taking 3 min to compute but I want results with in 30 seconds. what is the best way to optimize the code. (memory usage also).
def aspect_array(array): y,x=gradient(array) aspect=arctan2(y,x) for i in range(len(aspect)): for j in range(len(aspect)): if aspect[j](pi/2)): aspect[j]=(2*pi)-aspect[j]+(pi/2) else: aspect[j]=(pi/2)-aspect[j] return aspectHere I feel those if else loops are taking much more time. is there any other way to sort this problem. like a matrix multiplication kind of solution.
أكثر...
def aspect_array(array): y,x=gradient(array) aspect=arctan2(y,x) for i in range(len(aspect)): for j in range(len(aspect)): if aspect[j](pi/2)): aspect[j]=(2*pi)-aspect[j]+(pi/2) else: aspect[j]=(pi/2)-aspect[j] return aspectHere I feel those if else loops are taking much more time. is there any other way to sort this problem. like a matrix multiplication kind of solution.
أكثر...