Merge pull request #244 from Gattocrucco/alt-sol-87

Alternative solution to exercise 87
This commit is contained in:
Nicolas P. Rougier authored and GitHub committed 2025-08-26 11:07:22 +02:00
commit 5c3481111f
1 file changed
+2 -5
+2 -5
View File
@@ -1337,11 +1337,8 @@ k = 4
windows = np.lib.stride_tricks.sliding_window_view(Z, (k, k)) windows = np.lib.stride_tricks.sliding_window_view(Z, (k, k))
S = windows[::k, ::k, ...].sum(axis=(-2, -1)) S = windows[::k, ::k, ...].sum(axis=(-2, -1))
# Author: Jeff Luo (@Jeff1999) # alternative solution (by @Gattocrucco)
S = Z.reshape(4, 4, 4, 4).sum((1, 3))
Z = np.ones((16, 16))
k = 4
print(sliding_window_view(Z, window_shape=(k, k))[::k, ::k].sum(axis=(-2, -1)))
< q88 < q88
How to implement the Game of Life using numpy arrays? (★★★) How to implement the Game of Life using numpy arrays? (★★★)