我必须使用matplotlib中的contourf从函数返回的值x,y创建一个二维numpy数组,到目前为止我使用的是类似“C”的结构,它在Python中似乎效率很低:
dim_x = np.linspace(self.min_x, self.max_x, self.step)
dim_y = np.linspace(self.min_y, self.max_y, self.step)
X, Y = np.meshgrid(dim_x, dim_y)
len_x = len(dim_x)
len_y = len(dim_y)
a = np.zeros([len_x, len_y], dtype=complex)
for i, y in enumerate(dim_y):
for j, x in enumerate(dim_x):
a[i][j] = aux_functions.final_potential(complex(x, y), element_list)
cs = plt.contourf(X, Y, (a.real), 100)
如何以更 Pythonic 的方式完成此操作?
谢谢!