From 5ec27f54c8dc34e3d307bd66dc29585a74e70751 Mon Sep 17 00:00:00 2001 From: kuzand Date: Fri, 2 Nov 2018 15:23:51 +0200 Subject: [PATCH 1/4] Added another solution to question 96. --- 100_Numpy_exercises.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/100_Numpy_exercises.md b/100_Numpy_exercises.md index 14ae2c5..c93c54b 100644 --- a/100_Numpy_exercises.md +++ b/100_Numpy_exercises.md @@ -1156,6 +1156,11 @@ T = np.ascontiguousarray(Z).view(np.dtype((np.void, Z.dtype.itemsize * Z.shape[1 _, idx = np.unique(T, return_index=True) uZ = Z[idx] print(uZ) + +# Another solution, for NumPy >= 1.13 +# Author: Andreas Kouzelis +uZ = np.unique(Z, axis=0) +print(uZ) ``` #### 97. Considering 2 vectors A & B, write the einsum equivalent of inner, outer, sum, and mul function (★★★) From 5b18530d7992b8868a8d614cedf9927be70f907e Mon Sep 17 00:00:00 2001 From: kuzand Date: Fri, 2 Nov 2018 15:55:56 +0200 Subject: [PATCH 2/4] Another solution to question 96. We can use np.unique with axis=0 to return unique rows of an array. For NumPy >= 1.13 --- 100_Numpy_exercises.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/100_Numpy_exercises.md b/100_Numpy_exercises.md index c93c54b..1e4c220 100644 --- a/100_Numpy_exercises.md +++ b/100_Numpy_exercises.md @@ -1157,8 +1157,8 @@ _, idx = np.unique(T, return_index=True) uZ = Z[idx] print(uZ) -# Another solution, for NumPy >= 1.13 # Author: Andreas Kouzelis +# For NumPy >= 1.13 uZ = np.unique(Z, axis=0) print(uZ) ``` From 90f676235aa35c8f9861ac1c96684c34d1d312b0 Mon Sep 17 00:00:00 2001 From: kuzand Date: Fri, 2 Nov 2018 15:56:53 +0200 Subject: [PATCH 3/4] Update 100_Numpy_exercises.md --- 100_Numpy_exercises.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/100_Numpy_exercises.md b/100_Numpy_exercises.md index 1e4c220..c3ff2cc 100644 --- a/100_Numpy_exercises.md +++ b/100_Numpy_exercises.md @@ -1158,7 +1158,7 @@ uZ = Z[idx] print(uZ) # Author: Andreas Kouzelis -# For NumPy >= 1.13 +# NumPy >= 1.13 uZ = np.unique(Z, axis=0) print(uZ) ``` From 03b1a408f5eb0b9f0079a2bed0ac7cba3da22c41 Mon Sep 17 00:00:00 2001 From: kuzand Date: Fri, 2 Nov 2018 15:57:57 +0200 Subject: [PATCH 4/4] New hint for question 96 --- 100_Numpy_exercises_with_hint.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/100_Numpy_exercises_with_hint.md b/100_Numpy_exercises_with_hint.md index 43aaccb..e926efa 100644 --- a/100_Numpy_exercises_with_hint.md +++ b/100_Numpy_exercises_with_hint.md @@ -606,7 +606,7 @@ np.sqrt(-1) == np.emath.sqrt(-1) #### 96. Given a two dimensional array, how to extract unique rows? (★★★) -(**hint**: np.ascontiguousarray) +(**hint**: np.ascontiguousarray | np.unique)