Skip to content

Commit

Permalink
Fix helpers.hist_dist() crash in weight_initialization notebook
Browse files Browse the repository at this point in the history
The plt.hist function requires its "num" parameter to be an integer.
However, in helpers.hist_dist(), the argument value for this parameter
is calculated using regular ("/") division operator, which in Python 3
returns a float. This causes an exception when the value is passed
to plt.hist.

Note that this code would work correctly in Python 2, where the regular
division operator returns integers.

The fix here is trivial: simply use the integer division operator
("//"), which will return an integer in both Python 2 and 3.
  • Loading branch information
rogalskim committed May 15, 2020
1 parent 3a95d11 commit 03e1532
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion weight-initialization/helpers.py
Expand Up @@ -105,5 +105,5 @@ def hist_dist(title, distribution_tensor, hist_range=(-4, 4)):
Display histogram of values in a given distribution tensor
"""
plt.title(title)
plt.hist(distribution_tensor, np.linspace(*hist_range, num=len(distribution_tensor)/2))
plt.hist(distribution_tensor, np.linspace(*hist_range, num=len(distribution_tensor)//2))
plt.show()

0 comments on commit 03e1532

Please sign in to comment.