From 5837bcb4a8e0841be4c98ee8a163b51913008ca3 Mon Sep 17 00:00:00 2001 From: TheoCadene <129187267+TheoCadene@users.noreply.github.com> Date: Tue, 16 Dec 2025 17:06:09 +0100 Subject: [PATCH 1/3] UP my solution --- numpy_questions.py | 19 +++++++++++++++---- requirements.txt | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/numpy_questions.py b/numpy_questions.py index 07a10c1..167269f 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -40,7 +40,13 @@ def max_index(X): i = 0 j = 0 - # TODO + if not isinstance(X, np.ndarray): + raise ValueError("Input must be a numpy array") + + if X.ndim != 2: + raise ValueError("Input must be a 2D array.") + + i, j = np.unravel_index(np.argmax(X), X.shape) return i, j @@ -62,6 +68,11 @@ def wallis_product(n_terms): pi : float The approximation of order `n_terms` of pi using the Wallis product. """ - # XXX : The n_terms is an int that corresponds to the number of - # terms in the product. For example 10000. - return 0. + if n_terms < 0: + raise ValueError("n_terms must be a non-negative integer.") + + product = 1.0 + for i in range(1, n_terms + 1): + product *= (4.0 * i * i) / (4.0 * i * i - 1.0) + + return 2.0 * product diff --git a/requirements.txt b/requirements.txt index d850dbf..c6c4cdf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ numpy scipy scikit-learn pandas +pytest \ No newline at end of file From 4358ffe5e64eaee3002e41b5e2adf31bc459406f Mon Sep 17 00:00:00 2001 From: TheoCadene <129187267+TheoCadene@users.noreply.github.com> Date: Wed, 17 Dec 2025 13:50:13 +0100 Subject: [PATCH 2/3] UP my solution --- numpy_questions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/numpy_questions.py b/numpy_questions.py index 167269f..cf7ffc0 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -42,10 +42,10 @@ def max_index(X): if not isinstance(X, np.ndarray): raise ValueError("Input must be a numpy array") - + if X.ndim != 2: - raise ValueError("Input must be a 2D array.") - + raise ValueError("Input must be a 2D array.") + i, j = np.unravel_index(np.argmax(X), X.shape) return i, j From 5f76a7f49e22bf69c7735215cabcc0841c4ed9fa Mon Sep 17 00:00:00 2001 From: TheoCadene <129187267+TheoCadene@users.noreply.github.com> Date: Fri, 19 Dec 2025 14:16:05 +0100 Subject: [PATCH 3/3] trigger