From 340b50660364b4c96e3e25d8ebdf8d6905731847 Mon Sep 17 00:00:00 2001 From: Zieir Date: Mon, 15 Dec 2025 14:44:04 +0100 Subject: [PATCH 1/2] done --- numpy_questions.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/numpy_questions.py b/numpy_questions.py index 07a10c1..8a9e8c6 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -40,8 +40,14 @@ def max_index(X): i = 0 j = 0 - # TODO - + + if not isinstance(X, np.ndarray): + raise ValueError("This input is not a numpy array") + if X.ndim != 2 : + raise ValueError("Input is not 2D") + + arg = np.argmax(X) + i, j = np.unravel_index(arg, X.shape) return i, j @@ -62,6 +68,8 @@ 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. + p = 1.0 + if n_terms > 0: + for i in range(1, n_terms + 1): + p *= (2.0 * i / (2.0 * i - 1.0)) * (2.0 * i / (2.0 * i + 1.0)) + return 2.0 * p From 3788b18f05a30422ea6ac1ac3a4ece1b0699f103 Mon Sep 17 00:00:00 2001 From: Zieir Date: Fri, 19 Dec 2025 19:25:57 +0100 Subject: [PATCH 2/2] passed flake8 --- numpy_questions.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/numpy_questions.py b/numpy_questions.py index 8a9e8c6..efa42be 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -40,12 +40,10 @@ def max_index(X): i = 0 j = 0 - if not isinstance(X, np.ndarray): raise ValueError("This input is not a numpy array") - if X.ndim != 2 : + if X.ndim != 2: raise ValueError("Input is not 2D") - arg = np.argmax(X) i, j = np.unravel_index(arg, X.shape) return i, j