solutions update from 5c34811

This commit is contained in:
rougier
2025-08-26 09:07:46 +00:00
committed by github-actions[bot]
parent 5c3481111f
commit 19dcbdd422
4 changed files with 213 additions and 219 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1090,11 +1090,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)))
``` ```
#### 88. How to implement the Game of Life using numpy arrays? (★★★) #### 88. How to implement the Game of Life using numpy arrays? (★★★)
`No hints provided...` `No hints provided...`

View File

@@ -1090,11 +1090,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)))
``` ```
#### 88. How to implement the Game of Life using numpy arrays? (★★★) #### 88. How to implement the Game of Life using numpy arrays? (★★★)

View File

@@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "6f6a89e6", "id": "7e8b1da3",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 100 numpy exercises\n", "# 100 numpy exercises\n",
@@ -18,7 +18,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "4281e2bd", "id": "fe47c268",
"metadata": {}, "metadata": {},
"source": [ "source": [
"File automatically generated. See the documentation to update questions/answers/hints programmatically." "File automatically generated. See the documentation to update questions/answers/hints programmatically."
@@ -26,7 +26,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "46502bff", "id": "d6be3eba",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Run the `initialise.py` module, then call a random question with `pick()` an hint towards its solution with\n", "Run the `initialise.py` module, then call a random question with `pick()` an hint towards its solution with\n",
@@ -36,7 +36,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "4d7dd9e9", "id": "178fcfcd",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -46,7 +46,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "4bd2b4f7", "id": "747d40f8",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [