From 2e0dff8bd52562cfc18ce967da9536d9047393bd Mon Sep 17 00:00:00 2001 From: ChristopherTsa Date: Fri, 20 Dec 2024 23:02:19 +0100 Subject: [PATCH] UP my solution --- numpy_questions.py | 27 ++++++++++++++++++++++++++- requirements.txt | 2 ++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/numpy_questions.py b/numpy_questions.py index 07a10c1..5aeba01 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -41,6 +41,19 @@ def max_index(X): j = 0 # 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 2-dimensional.") + + max_value = X[i, j] + + for x in range(X.shape[0]): + for y in range(X.shape[1]): + if X[x, y] > max_value: + max_value = X[x, y] + i, j = x, y return i, j @@ -64,4 +77,16 @@ 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. + + if n_terms < 0: + raise ValueError("n_term cannot be negative") + + product = 1 + + if n_terms == 0: + return product*2 + + for i in range(1, n_terms + 1): + product *= (4 * i**2) / (4 * i**2 - 1) + + return product*2 diff --git a/requirements.txt b/requirements.txt index d850dbf..8e1cc0f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,5 @@ numpy scipy scikit-learn pandas +pytest +flake8 \ No newline at end of file