【发布时间】:2021-12-17 17:39:03
【问题描述】:
我正在使用 defalutdict(代码中的 ddtype)对象,它基本上作为一个 3D 函数,通过将每对自然元素映射到一个实数。
但如果我尝试使用 matplotlib 打印所有具有某些特征的元素:
import matplotlib.pyplot as plt
from collections import defaultdict
ddtype = defaultdict(int, {(1,1):2.2,(1,2):0.7,(2,1):0.9,(2,2):1.3})
for i in range(1,3):
for j in range(1,3):
if (ddtype[i,j] > 1.5):
plt.plot((i,j),'k+')
plt.show()
# The plot is saved but not here
即使我经常清除内存,程序也会变得非常慢(对于大范围的循环)。是否有更有效的方法来编写上述循环? 提前谢谢你
【问题讨论】:
标签: python matplotlib defaultdict