美文网首页
tqdm && progressbar的使用

tqdm && progressbar的使用

作者: csuhan | 来源:发表于2019-10-08 21:22 被阅读0次

tqdm

from tqdm import tqdm
import time

for i in tqdm(range(1000)):
    time.sleep(0.01)

效果如下:

37%|█████████                     | 370/1000 [00:03<00:06, 98.89it/s]

只要是可迭代的对象,均可使用使用tqdm

progressbar

import time
from tqdm import tqdm
from progressbar import *

for i in tqdm(range(100)):
    time.sleep(0.02)

widgets=['Epoch i ',Percentage(),' ',Bar(),' ',ETA()]
pb = ProgressBar(widgets=widgets)
for i in pb(range(500)):
    time.sleep(0.02)

输出:

100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 100/100 [00:02<00:00, 49.60it/s]
Epoch i 100% |####################################################################################################################################################| Time: 0:00:10

其中widgets是一个数组,可以任意组合文字和函数,Percentage()是百分比,Bar()是进度条,ETA()是剩余时间。

相关文章

网友评论

      本文标题:tqdm && progressbar的使用

      本文链接:https://www.haomeiwen.com/subject/oadipctx.html