From 301e0eb61e41a1c000736901a0b3d11e3b0fb6fe Mon Sep 17 00:00:00 2001 From: Gattocrucco Date: Tue, 26 Aug 2025 00:16:34 +0200 Subject: [PATCH] further simplification to the alt solution of 87 The initial formulation contained a redundant `swapaxes`. --- 100_Numpy_exercises_with_hints_with_solutions.md | 2 +- 100_Numpy_exercises_with_solutions.md | 2 +- source/exercises100.ktx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/100_Numpy_exercises_with_hints_with_solutions.md b/100_Numpy_exercises_with_hints_with_solutions.md index d3ddde2..29f4f71 100644 --- a/100_Numpy_exercises_with_hints_with_solutions.md +++ b/100_Numpy_exercises_with_hints_with_solutions.md @@ -1087,7 +1087,7 @@ windows = np.lib.stride_tricks.sliding_window_view(Z, (k, k)) S = windows[::k, ::k, ...].sum(axis=(-2, -1)) # alternative solution (by @Gattocrucco) -S = Z.reshape(4, 4, 4, 4).swapaxes(1, 2).sum((2, 3)) +S = Z.reshape(4, 4, 4, 4).sum((1, 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 f366208..af8413c 100644 --- a/100_Numpy_exercises_with_solutions.md +++ b/100_Numpy_exercises_with_solutions.md @@ -1087,7 +1087,7 @@ windows = np.lib.stride_tricks.sliding_window_view(Z, (k, k)) S = windows[::k, ::k, ...].sum(axis=(-2, -1)) # alternative solution (by @Gattocrucco) -S = Z.reshape(4, 4, 4, 4).swapaxes(1, 2).sum((2, 3)) +S = Z.reshape(4, 4, 4, 4).sum((1, 3)) ``` #### 88. How to implement the Game of Life using numpy arrays? (★★★) diff --git a/source/exercises100.ktx b/source/exercises100.ktx index 3f71c5d..a0725c6 100644 --- a/source/exercises100.ktx +++ b/source/exercises100.ktx @@ -1334,7 +1334,7 @@ windows = np.lib.stride_tricks.sliding_window_view(Z, (k, k)) S = windows[::k, ::k, ...].sum(axis=(-2, -1)) # alternative solution (by @Gattocrucco) -S = Z.reshape(4, 4, 4, 4).swapaxes(1, 2).sum((2, 3)) +S = Z.reshape(4, 4, 4, 4).sum((1, 3)) < q88 How to implement the Game of Life using numpy arrays? (★★★)