From fb72a9033d1158894fd9b99ec2034b152b6a6325 Mon Sep 17 00:00:00 2001 From: Martin Simonoviez Date: Fri, 20 Dec 2024 00:17:33 +0100 Subject: [PATCH 1/6] UP my solution --- numpy_questions.py | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/numpy_questions.py b/numpy_questions.py index 07a10c1..4a42960 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -1,3 +1,5 @@ + + """Assignment - using numpy and making a PR. The goals of this assignment are: @@ -15,7 +17,12 @@ This will be enforced with `flake8`. You can check that there is no flake8 errors by calling `flake8` at the root of the repo. """ -import numpy as np + +import os + +os.chdir( + "/Users/martinsimonoviez/Desktop/IODAA" + + "/cours/datacamp-master/2024-assignment-numpy") def max_index(X): @@ -37,12 +44,20 @@ def max_index(X): If the input is not a numpy array or if the shape is not 2D. """ + if "numpy" in str(type(X)): + raise ValueError('None') + if X.ndim != 2: + raise ValueError('Not in 2D') i = 0 j = 0 - - # TODO - - return i, j + max_local = X[0, 0] + for k in range(X.shape[0]): + for m in range(X.shape[1]): + if X[k, m] > max_local: + max_local = X[k, m] + i = k + j = m + return(i, j) def wallis_product(n_terms): @@ -62,6 +77,9 @@ 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. +# XXX : The n_terms is an int that corresponds to the number of +# terms in the product. For example 10000. + resultat = 2 + for k in range(n_terms): + resultat = resultat*(4*((k+1)**2)/((4*((k+1)**2)-1))) + return resultat From cea4f045e3a8ba8b1e39e2aa043ebce1bcab0869 Mon Sep 17 00:00:00 2001 From: Martin Simonoviez Date: Wed, 25 Dec 2024 23:03:53 +0100 Subject: [PATCH 2/6] UP solution 2 --- numpy_questions.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/numpy_questions.py b/numpy_questions.py index 4a42960..def49e7 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -18,12 +18,6 @@ errors by calling `flake8` at the root of the repo. """ -import os - -os.chdir( - "/Users/martinsimonoviez/Desktop/IODAA" + - "/cours/datacamp-master/2024-assignment-numpy") - def max_index(X): """Return the index of the maximum in a numpy array. From 32e27a06bed6bc294f4a32595212b8e99ea011f5 Mon Sep 17 00:00:00 2001 From: Martin Simonoviez Date: Wed, 25 Dec 2024 23:08:24 +0100 Subject: [PATCH 3/6] UP solution 2 --- numpy_questions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/numpy_questions.py b/numpy_questions.py index def49e7..739369b 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -45,13 +45,13 @@ def max_index(X): i = 0 j = 0 max_local = X[0, 0] - for k in range(X.shape[0]): - for m in range(X.shape[1]): + for k in range(X.shape[0]+1): + for m in range(X.shape[1]+1): if X[k, m] > max_local: max_local = X[k, m] i = k j = m - return(i, j) + return (i, j) def wallis_product(n_terms): From 97efcfcea30fdd36ba20864286c354805128e0eb Mon Sep 17 00:00:00 2001 From: Martin Simonoviez Date: Wed, 25 Dec 2024 23:10:25 +0100 Subject: [PATCH 4/6] UP solution 2 --- numpy_questions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numpy_questions.py b/numpy_questions.py index 739369b..2612a13 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -45,8 +45,8 @@ def max_index(X): i = 0 j = 0 max_local = X[0, 0] - for k in range(X.shape[0]+1): - for m in range(X.shape[1]+1): + for k in range(X.shape[0]): + for m in range(X.shape[1]): if X[k, m] > max_local: max_local = X[k, m] i = k From 5d583bf0f73d1221ce7c0290c4bb7d3729defac3 Mon Sep 17 00:00:00 2001 From: Martin Simonoviez Date: Wed, 25 Dec 2024 23:14:32 +0100 Subject: [PATCH 5/6] UP solution 2 --- numpy_questions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numpy_questions.py b/numpy_questions.py index 2612a13..0b1491b 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -38,7 +38,7 @@ def max_index(X): If the input is not a numpy array or if the shape is not 2D. """ - if "numpy" in str(type(X)): + if "numpy" not in str(type(X)): raise ValueError('None') if X.ndim != 2: raise ValueError('Not in 2D') @@ -76,4 +76,4 @@ def wallis_product(n_terms): resultat = 2 for k in range(n_terms): resultat = resultat*(4*((k+1)**2)/((4*((k+1)**2)-1))) - return resultat + return resultat \ No newline at end of file From 8932f566f00e7e07ad806ebb1481357e230b28b3 Mon Sep 17 00:00:00 2001 From: Martin Simonoviez Date: Wed, 25 Dec 2024 23:15:46 +0100 Subject: [PATCH 6/6] UP solution 2 --- numpy_questions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numpy_questions.py b/numpy_questions.py index 0b1491b..b3b9d0f 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -76,4 +76,4 @@ def wallis_product(n_terms): resultat = 2 for k in range(n_terms): resultat = resultat*(4*((k+1)**2)/((4*((k+1)**2)-1))) - return resultat \ No newline at end of file + return resultat