小测验:使用 %lprun 的步骤
下面是 convert_units() 函数,用于将我们最喜爱的超级英雄的身高和体重从公制单位转换为英制单位。
def convert_units(heroes, heights, weights):
new_hts = [ht * 0.39370 for ht in heights]
new_wts = [wt * 2.20462 for wt in weights]
hero_data = {}
for i,hero in enumerate(heroes):
hero_data[hero] = (new_hts[i], new_wts[i])
return hero_data
假设您有一个超级英雄列表(命名为 heroes),以及每位英雄的身高(厘米)和体重(千克),并分别以 NumPy 数组(命名为 hts 和 wts)的形式加载。
要想看到逐行运行时间,针对您的超级英雄数据对 convert_units() 函数进行性能分析,您需要执行哪些必要步骤?
本练习是课程的一部分
