Skip to content

Commit f0756ce

Browse files
authored
Update nn_tutorial.py
Fix to #1303 "add pyplot.show() in beginner tutorial." Comments to issue suggested manually commenting out pyplot.show for users not using colab. Instead, suggest change that imports colab and does nothing if user is running notebook on colab, otherwise it runs pyplot.show() (such as when running on a local machine). This way, manual editing of notebook is not required, colab users are undisturbed and local users get pyplot.show.
1 parent 921f4fb commit f0756ce

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

beginner_source/nn_tutorial.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@
7575
import numpy as np
7676

7777
pyplot.imshow(x_train[0].reshape((28, 28)), cmap="gray")
78+
# pyplot.show() only if not on colab
79+
try:
80+
import google.colab
81+
except ImportError:
82+
pyplot.show()
83+
pass
7884
print(x_train.shape)
7985

8086
###############################################################################

0 commit comments

Comments
 (0)