From 2c738466acae77bb4c59b30909f3872224182891 Mon Sep 17 00:00:00 2001 From: Ahmed-Yassine Chraa Date: Mon, 16 Dec 2024 10:12:25 +0100 Subject: [PATCH] UP Solution Ahmedyassi02 --- numpy_questions.py | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/numpy_questions.py b/numpy_questions.py index 07a10c1..b3fbad2 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -39,10 +39,25 @@ def max_index(X): """ i = 0 j = 0 + max = -np.inf - # TODO + if not isinstance(X, np.ndarray): + raise ValueError("Input must be a numpy array") - return i, j + if len(X.shape) != 2: + raise ValueError("Input must be a 2D array") + + while i < X.shape[0]: + while j < X.shape[1]: + if X[i, j] > max: + max = X[i, j] + i_max = i + j_max = j + j += 1 + i += 1 + j = 0 + + return i_max, j_max def wallis_product(n_terms): @@ -64,4 +79,15 @@ def wallis_product(n_terms): """ # XXX : The n_terms is an int that corresponds to the number of # terms in the product. For example 10000. - return 0. + + terms = 1 + pi = 1 + + if n_terms == 0: + return 2 + + while terms <= n_terms: + pi = pi * (4*terms**2)/(4*terms**2-1) + terms = terms + 1 + + return pi*2