From 3e936d9be65faff6d6c2b6801d561f058dcf0e15 Mon Sep 17 00:00:00 2001 From: Antoine2596 Date: Thu, 19 Dec 2024 10:02:07 +0100 Subject: [PATCH 1/2] UP my solution --- numpy_questions.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/numpy_questions.py b/numpy_questions.py index 07a10c1..d03e189 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -37,12 +37,22 @@ def max_index(X): If the input is not a numpy array or if the shape is not 2D. """ - i = 0 - j = 0 - # TODO + if not isinstance(X, np.ndarray): + raise ValueError("the input is not a numpy array") + if X.ndim != 2: + raise ValueError("the shape is not 2D") + max_value = None + i, j = np.array(X).shape - return i, j + max_value = None + for x in range(i): + for y in range(j): + cell_value = X[x][y] + if max_value is None or cell_value > max_value: + max_value = cell_value + i_max, j_max = x, y + return i_max, j_max def wallis_product(n_terms): @@ -63,5 +73,11 @@ def wallis_product(n_terms): 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. + # terms in the product. For example 10000.* + if n_terms == 0: + pi_approx = 2 + else: + pi_approx = 2 + for n in range(1, n_terms + 1): + pi_approx *= (4 * n ** 2) / (4 * (n ** 2) - 1) + return pi_approx From 7140d2afd84fa87f146d25306eb1d8121771b671 Mon Sep 17 00:00:00 2001 From: Antoine2596 Date: Thu, 19 Dec 2024 21:31:50 +0100 Subject: [PATCH 2/2] UP my solution --- numpy_questions.py | 1 - 1 file changed, 1 deletion(-) diff --git a/numpy_questions.py b/numpy_questions.py index d03e189..e23aab1 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -37,7 +37,6 @@ def max_index(X): If the input is not a numpy array or if the shape is not 2D. """ - if not isinstance(X, np.ndarray): raise ValueError("the input is not a numpy array") if X.ndim != 2: