I have to do a summation over 2 indices in a 2D plane and in each point in space I have to get a value of a function.
The simplest way and the only way I know how to do it was with 4 for loops. It works well but it is extremely slow. Do you have any sugestions how to do it faster.
Note that "size" defines the step I am using and is the size of my sistem in arbitrary units and "n_0" is a list of lists and is an input parameter which is also dependent on the coordinates x in y.
for x in range(size):
for y in range(size):
for x_ in range(size):
for y_ in range(size):
if x == x_ and y == y_:
pass
else:
value = n_0[x][y] * N / math.sqrt((x - x_)**2 + (y - y_)**2)
print(value)
EDIT: I dont know why this was marked a duplicate because my problem is not being more concise with my syntax. My problem is that the code no matter what the syntax is is O(n^4) and I need to reduce this.