From 9b248dd3de65802e472501c745f1069f4560df77 Mon Sep 17 00:00:00 2001 From: ibah Date: Thu, 25 Aug 2016 14:52:59 +0200 Subject: [PATCH] Alternative solution to 'Compare random arrays' plus an explanation --- 100 Numpy exercises.ipynb | 5 +++++ 100 Numpy exercises.md | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/100 Numpy exercises.ipynb b/100 Numpy exercises.ipynb index 4b1a28a2..31706ea6 100644 --- a/100 Numpy exercises.ipynb +++ b/100 Numpy exercises.ipynb @@ -855,8 +855,13 @@ "source": [ "A = np.random.randint(0,2,5)\n", "B = np.random.randint(0,2,5)\n", + "# Assuming identical shape of the arrays and a tolerance for the comparison of values" "equal = np.allclose(A,B)\n", "print(equal)" + "\n" + "# Checking both the shape and the element values, no tolerance (values have to be exactly equal)" + "equal = np.array_equal(A,B)" + "print(equal)" ] }, { diff --git a/100 Numpy exercises.md b/100 Numpy exercises.md index 0cf071d5..1dcc369d 100644 --- a/100 Numpy exercises.md +++ b/100 Numpy exercises.md @@ -387,8 +387,13 @@ np.add.reduce(Z) ```python A = np.random.randint(0,2,5) B = np.random.randint(0,2,5) +# Assuming identical shape of the arrays and a tolerance for the comparison of values equal = np.allclose(A,B) print(equal) + +# Checking both the shape and the element values, no tolerance (values have to be exactly equal) +equal = np.array_equal(A,B) +print(equal) ``` #### 43. Make an array immutable (read-only) (★★☆)