用来添加一个索引
-
>>>seasons = ['Spring', 'Summer', 'Fall', 'Winter']
-
>>> list(enumerate(seasons))
-
[(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
-
>>> list(enumerate(seasons, start=1)) # 下标从 1 开始
-
[(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]
比如循环
-
>>>seq = ['one', 'two', 'three']
-
>>> for i, element in enumerate(seq):
-
... print i, element
-
...
-
0 one
-
1 two
-
2 three
深度学习批量学习
step就是索引
-
for epoch in range(3):
-
for step, (batch_x, batch_y) in enumerate(loader):
-
# 训练
-
print('Epoch: ', epoch, '| Step: ', step, '| batch x: ',
-
batch_x.numpy(), '| batch y: ', batch_y.numpy())
文章来源: kings.blog.csdn.net,作者:人工智能博士,版权归原作者所有,如需转载,请联系作者。
原文链接:kings.blog.csdn.net/article/details/109229221