From 37e7fe2563ad126135e65e35350819cceac0caa2 Mon Sep 17 00:00:00 2001 From: ibah Date: Tue, 29 Nov 2016 13:09:51 +0100 Subject: [PATCH 1/2] generalizing the solution to the 'extract rows with unequal values' exercise --- 100 Numpy exercises.ipynb | 4 +--- 100 Numpy exercises.md | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/100 Numpy exercises.ipynb b/100 Numpy exercises.ipynb index 7affa60..f736fd2 100644 --- a/100 Numpy exercises.ipynb +++ b/100 Numpy exercises.ipynb @@ -2149,9 +2149,7 @@ "# Author: Robert Kern\n", "\n", "Z = np.random.randint(0,5,(10,3))\n", - "E = np.logical_and.reduce(Z[:,1:] == Z[:,:-1], axis=1)\n", - "U = Z[~E]\n", - "print(Z)\n", + "U = Z[Z.max(axis=1) != Z.min(axis=1),:]\n", "print(U)" ] }, diff --git a/100 Numpy exercises.md b/100 Numpy exercises.md index cefbc41..6a833c3 100644 --- a/100 Numpy exercises.md +++ b/100 Numpy exercises.md @@ -1108,9 +1108,7 @@ print(rows) # Author: Robert Kern Z = np.random.randint(0,5,(10,3)) -E = np.logical_and.reduce(Z[:,1:] == Z[:,:-1], axis=1) -U = Z[~E] -print(Z) +U = Z[Z.max(axis=1) != Z.min(axis=1),:] print(U) ``` From 946647cb400154b1651fad2b1da1bea873290750 Mon Sep 17 00:00:00 2001 From: ibah Date: Thu, 1 Dec 2016 13:42:52 +0100 Subject: [PATCH 2/2] Adding an alternative solution to the 'extract rows with unequal values' exercise --- 100 Numpy exercises.ipynb | 6 ++++++ 100 Numpy exercises.md | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/100 Numpy exercises.ipynb b/100 Numpy exercises.ipynb index f736fd2..c24372a 100644 --- a/100 Numpy exercises.ipynb +++ b/100 Numpy exercises.ipynb @@ -2149,6 +2149,12 @@ "# Author: Robert Kern\n", "\n", "Z = np.random.randint(0,5,(10,3))\n", + "print(Z)\n", + "# solution for arrays of all dtypes (including string arrays and record arrays)\n", + "E = np.all(Z[:,1:] == Z[:,:-1], axis=1)\n", + "U = Z[~E]\n", + "print(U)\n", + "# soluiton for numerical arrays only, will work for any number of columns in Z\n", "U = Z[Z.max(axis=1) != Z.min(axis=1),:]\n", "print(U)" ] diff --git a/100 Numpy exercises.md b/100 Numpy exercises.md index 6a833c3..359e69a 100644 --- a/100 Numpy exercises.md +++ b/100 Numpy exercises.md @@ -1108,6 +1108,12 @@ print(rows) # Author: Robert Kern Z = np.random.randint(0,5,(10,3)) +print(Z) +# solution for arrays of all dtypes (including string arrays and record arrays) +E = np.all(Z[:,1:] == Z[:,:-1], axis=1) +U = Z[~E] +print(U) +# soluiton for numerical arrays only, will work for any number of columns in Z U = Z[Z.max(axis=1) != Z.min(axis=1),:] print(U) ```