diff --git a/100_Numpy_exercises_with_hints_with_solutions.md b/100_Numpy_exercises_with_hints_with_solutions.md index 409c00f..d3ddde2 100644 --- a/100_Numpy_exercises_with_hints_with_solutions.md +++ b/100_Numpy_exercises_with_hints_with_solutions.md @@ -1086,11 +1086,8 @@ k = 4 windows = np.lib.stride_tricks.sliding_window_view(Z, (k, k)) S = windows[::k, ::k, ...].sum(axis=(-2, -1)) -# Author: Jeff Luo (@Jeff1999) - -Z = np.ones((16, 16)) -k = 4 -print(sliding_window_view(Z, window_shape=(k, k))[::k, ::k].sum(axis=(-2, -1))) +# alternative solution (by @Gattocrucco) +S = Z.reshape(4, 4, 4, 4).swapaxes(1, 2).sum((2, 3)) ``` #### 88. How to implement the Game of Life using numpy arrays? (★★★) `No hints provided...` diff --git a/100_Numpy_exercises_with_solutions.md b/100_Numpy_exercises_with_solutions.md index c7285d2..f366208 100644 --- a/100_Numpy_exercises_with_solutions.md +++ b/100_Numpy_exercises_with_solutions.md @@ -1086,11 +1086,8 @@ k = 4 windows = np.lib.stride_tricks.sliding_window_view(Z, (k, k)) S = windows[::k, ::k, ...].sum(axis=(-2, -1)) -# Author: Jeff Luo (@Jeff1999) - -Z = np.ones((16, 16)) -k = 4 -print(sliding_window_view(Z, window_shape=(k, k))[::k, ::k].sum(axis=(-2, -1))) +# alternative solution (by @Gattocrucco) +S = Z.reshape(4, 4, 4, 4).swapaxes(1, 2).sum((2, 3)) ``` #### 88. How to implement the Game of Life using numpy arrays? (★★★) diff --git a/source/exercises100.ktx b/source/exercises100.ktx index d1457aa..3f71c5d 100644 --- a/source/exercises100.ktx +++ b/source/exercises100.ktx @@ -1333,11 +1333,8 @@ k = 4 windows = np.lib.stride_tricks.sliding_window_view(Z, (k, k)) S = windows[::k, ::k, ...].sum(axis=(-2, -1)) -# Author: Jeff Luo (@Jeff1999) - -Z = np.ones((16, 16)) -k = 4 -print(sliding_window_view(Z, window_shape=(k, k))[::k, ::k].sum(axis=(-2, -1))) +# alternative solution (by @Gattocrucco) +S = Z.reshape(4, 4, 4, 4).swapaxes(1, 2).sum((2, 3)) < q88 How to implement the Game of Life using numpy arrays? (★★★)