Skip to content

Commit 5e41a58

Browse files
committed
Exercices complétés
Signed-off-by: CyprienDS <mr.cds29@gmail.com>
1 parent d31f7ef commit 5e41a58

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

numpy_questions.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
The goals of this assignment are:
44
* Use numpy in practice with two easy exercises.
55
* Use automated tools to validate the code (`pytest` and `flake8`)
6-
* Submit a Pull-Request on github to practice `git`.
6+
* Submit a Pull-Request on gitHub to practice `git`.
77
88
The two functions below are skeleton functions. The docstrings explain what
99
are the inputs, the outputs and the expected error. Fill the function to
@@ -15,6 +15,7 @@
1515
This will be enforced with `flake8`. You can check that there is no flake8
1616
errors by calling `flake8` at the root of the repo.
1717
"""
18+
1819
import numpy as np
1920

2021

@@ -40,7 +41,21 @@ def max_index(X):
4041
i = 0
4142
j = 0
4243

44+
4345
# TODO
46+
if not isinstance(X, np.ndarray):
47+
raise ValueError("L'argument doit être une numpy array.")
48+
49+
forme = X.shape
50+
51+
if len(forme) != 2:
52+
raise ValueError("L'argument doit être en 2D.")
53+
54+
n_samples, n_features = forme
55+
56+
index = np.argmax(X)
57+
i = int(index//n_features)
58+
j = int(index%n_features)
4459

4560
return i, j
4661

@@ -62,6 +77,11 @@ def wallis_product(n_terms):
6277
pi : float
6378
The approximation of order `n_terms` of pi using the Wallis product.
6479
"""
65-
# XXX : The n_terms is an int that corresponds to the number of
66-
# terms in the product. For example 10000.
67-
return 0.
80+
if n_terms == 0:
81+
return 2
82+
83+
wal_pro = 1
84+
for i in range(1, n_terms + 1):
85+
wal_pro *= (4 * i ** 2) / ((4 * i ** 2) - 1)
86+
87+
return wal_pro * 2.

0 commit comments

Comments
 (0)