From 03e1532818277a2bdbbd536a4ef31e8eccbe6491 Mon Sep 17 00:00:00 2001 From: rogalskim Date: Fri, 15 May 2020 14:31:38 +0200 Subject: [PATCH] Fix helpers.hist_dist() crash in weight_initialization notebook 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. --- weight-initialization/helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weight-initialization/helpers.py b/weight-initialization/helpers.py index 57f338f720..545c3f04b2 100644 --- a/weight-initialization/helpers.py +++ b/weight-initialization/helpers.py @@ -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() \ No newline at end of file