Skip to content

Commit 28e0e44

Browse files
committed
iter.next() to next(iter)
The new pytorch version does not allow the old command and causes the code to return errors when running. It is a small fix, that will especially help beginners.
1 parent e6dd99c commit 28e0e44

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

09_dataloader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __len__(self):
6666

6767
# convert to an iterator and look at one random sample
6868
dataiter = iter(train_loader)
69-
data = dataiter.next()
69+
data = next(dataiter)
7070
features, labels = data
7171
print(features, labels)
7272

@@ -97,6 +97,6 @@ def __len__(self):
9797

9898
# look at one random sample
9999
dataiter = iter(train_loader)
100-
data = dataiter.next()
100+
data = next(dataiter)
101101
inputs, targets = data
102102
print(inputs.shape, targets.shape)

13_feedforward.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
shuffle=False)
3636

3737
examples = iter(test_loader)
38-
example_data, example_targets = examples.next()
38+
example_data, example_targets = next(examples)
3939

4040
for i in range(6):
4141
plt.subplot(2,3,i+1)

14_cnn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def imshow(img):
4545

4646
# get some random training images
4747
dataiter = iter(train_loader)
48-
images, labels = dataiter.next()
48+
images, labels = next(dataiter)
4949

5050
# show images
5151
imshow(torchvision.utils.make_grid(images))

16_tensorboard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
shuffle=False)
4444

4545
examples = iter(test_loader)
46-
example_data, example_targets = examples.next()
46+
example_data, example_targets = next(examples)
4747

4848
for i in range(6):
4949
plt.subplot(2,3,i+1)

0 commit comments

Comments
 (0)