From be36dafae84929cd460928ae6313e7eed4cec361 Mon Sep 17 00:00:00 2001 From: TitouanCh Date: Mon, 16 Dec 2024 11:41:57 +0100 Subject: [PATCH 1/6] max_index --- numpy_questions.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/numpy_questions.py b/numpy_questions.py index 07a10c1..41fce6f 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -40,7 +40,16 @@ def max_index(X): i = 0 j = 0 - # TODO + if not(isinstance(X, np.ndarray)): raise(ValueError) + if X.ndim != 2: raise(ValueError) + + m = None + for (idx, a) in enumerate(X.ravel()): + if m is None: m = a + elif a > m: + m = a + i = idx % X.shape[1] + j = int(np.floor(idx / X.shape[1])) return i, j From 67a4b2715571727019243174ae38969d5e5013b3 Mon Sep 17 00:00:00 2001 From: TitouanCh Date: Mon, 16 Dec 2024 11:44:32 +0100 Subject: [PATCH 2/6] small fix --- numpy_questions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numpy_questions.py b/numpy_questions.py index 41fce6f..322e368 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -48,8 +48,8 @@ def max_index(X): if m is None: m = a elif a > m: m = a - i = idx % X.shape[1] - j = int(np.floor(idx / X.shape[1])) + j = idx % X.shape[1] + i = int(np.floor(idx / X.shape[1])) return i, j From c7e911dc2d9995ac2ecf02da87b01c6966627a0f Mon Sep 17 00:00:00 2001 From: TitouanCh Date: Mon, 16 Dec 2024 13:53:00 +0100 Subject: [PATCH 3/6] wallis --- numpy_questions.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/numpy_questions.py b/numpy_questions.py index 322e368..5e58b4b 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -73,4 +73,9 @@ 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) + pi = 1 + for i in range(1, n_terms + 1): + pi *= (4 * i ** 2) / (4 * i ** 2 - 1) + pi *= 2 + return pi From 515ab0ca0c27e74fc8c5a3b61bf97d78346c4728 Mon Sep 17 00:00:00 2001 From: TitouanCh Date: Mon, 16 Dec 2024 13:57:05 +0100 Subject: [PATCH 4/6] formatting --- numpy_questions.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/numpy_questions.py b/numpy_questions.py index 5e58b4b..9848101 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -40,12 +40,15 @@ def max_index(X): i = 0 j = 0 - if not(isinstance(X, np.ndarray)): raise(ValueError) - if X.ndim != 2: raise(ValueError) + if not isinstance(X, np.ndarray): + raise ValueError + if X.ndim != 2: + raise ValueError m = None for (idx, a) in enumerate(X.ravel()): - if m is None: m = a + if m is None: + m = a elif a > m: m = a j = idx % X.shape[1] @@ -73,7 +76,8 @@ 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. - if n_terms < 0: raise(ValueError) + if n_terms < 0: + raise ValueError pi = 1 for i in range(1, n_terms + 1): pi *= (4 * i ** 2) / (4 * i ** 2 - 1) From 6d60aa3e7e016ffa65e765ebe6ff11e47a49d110 Mon Sep 17 00:00:00 2001 From: TitouanCh Date: Mon, 16 Dec 2024 13:59:48 +0100 Subject: [PATCH 5/6] UP my solution --- numpy_questions.py | 1 + 1 file changed, 1 insertion(+) diff --git a/numpy_questions.py b/numpy_questions.py index 9848101..1e27f3b 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -83,3 +83,4 @@ def wallis_product(n_terms): pi *= (4 * i ** 2) / (4 * i ** 2 - 1) pi *= 2 return pi + From e2823a0bdf3029dea2e29e97df47cffa4d368ea1 Mon Sep 17 00:00:00 2001 From: TitouanCH Date: Wed, 18 Dec 2024 01:36:55 +0100 Subject: [PATCH 6/6] workflow plz --- numpy_questions.py | 1 - 1 file changed, 1 deletion(-) diff --git a/numpy_questions.py b/numpy_questions.py index 1e27f3b..9848101 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -83,4 +83,3 @@ def wallis_product(n_terms): pi *= (4 * i ** 2) / (4 * i ** 2 - 1) pi *= 2 return pi -