From 88c2f7ff8f9a3ac4bc1bc9e064eb587d9328ba9d Mon Sep 17 00:00:00 2001 From: AdrienBouchet1 Date: Fri, 20 Dec 2024 21:30:28 +0100 Subject: [PATCH 1/2] ajout --- numpy_questions.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/numpy_questions.py b/numpy_questions.py index 07a10c1..9f999cd 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -29,7 +29,7 @@ def max_index(X): Returns ------- (i, j) : tuple(int) - The row and columnd index of the maximum. + The row and column index of the maximum. Raises ------ @@ -39,9 +39,11 @@ def max_index(X): """ i = 0 j = 0 - - # TODO - + if type(X) is not np.ndarray: + raise ValueError + if len(X.shape) != 2: + raise ValueError + i, j = np.unravel_index(np.argmax(X), X.shape) return i, j @@ -62,6 +64,12 @@ 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 type(n_terms) is not int: + raise TypeError + product = 1 + for n in range(0, n_terms): + product = product*((4*((n+1)**2))/(4*((n+1)**2)-1)) + return product*2 From 61a7d3ac2e1539dcad8615ae91911af4b1f99a9f Mon Sep 17 00:00:00 2001 From: AdrienBouchet1 Date: Fri, 20 Dec 2024 21:33:35 +0100 Subject: [PATCH 2/2] ajout2 --- numpy_questions.py | 1 - 1 file changed, 1 deletion(-) diff --git a/numpy_questions.py b/numpy_questions.py index 9f999cd..ed1bfd5 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -64,7 +64,6 @@ 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. if type(n_terms) is not int: