A = np.exp(-0.5 * ((elem[0] - array2[:, (0)]) / elem[3]) ** 2)
B = np.exp(-0.5 * ((elem[1] - array2[:, (1)]) / elem[3]) ** 2)
array3 = A * B
sum_list3 = max(array3.sum(), 1e-06)
list4.append(sum_list3)
Speed up nested for loop with elements exponentiation