当前位置:   article > 正文

Python | enumerate() 函数_enumerate(loader)

enumerate(loader)

用来添加一个索引

  1. >>>seasons = ['Spring', 'Summer', 'Fall', 'Winter']
  2. >>> list(enumerate(seasons))
  3. [(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
  4. >>> list(enumerate(seasons, start=1)) # 下标从 1 开始
  5. [(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]

比如循环

  1. >>>seq = ['one', 'two', 'three']
  2. >>> for i, element in enumerate(seq):
  3. ... print i, element
  4. ...
  5. 0 one
  6. 1 two
  7. 2 three

深度学习批量学习

step就是索引

  1. for epoch in range(3):
  2. for step, (batch_x, batch_y) in enumerate(loader):
  3. # 训练
  4. print('Epoch: ', epoch, '| Step: ', step, '| batch x: ',
  5. batch_x.numpy(), '| batch y: ', batch_y.numpy())

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/101848
推荐阅读
相关标签
  

闽ICP备14008679号