From ae60533a8e5db3737650e31eae1ebc41ce41ac22 Mon Sep 17 00:00:00 2001 From: Khadija Date: Thu, 19 Dec 2024 18:54:16 +0100 Subject: [PATCH] UP my solution --- numpy_questions.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/numpy_questions.py b/numpy_questions.py index 07a10c1..ac3be90 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -42,6 +42,15 @@ def max_index(X): # TODO + if not isinstance(X, np.ndarray): + raise ValueError("Input must be a numpy array.") + if X.ndim != 2: + raise ValueError("Input array must be 2D.") + + max_idx = np.argmax(X) + + i, j = divmod(max_idx, X.shape[1]) + return i, j @@ -64,4 +73,7 @@ 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. + pi = 1 + for i in range(1, n_terms + 1): + pi = pi * (4 * (i**2) / (4 * (i**2) - 1)) + return pi * 2