3
3
The goals of this assignment are:
4
4
* Use numpy in practice with two easy exercises.
5
5
* 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`.
7
7
8
8
The two functions below are skeleton functions. The docstrings explain what
9
9
are the inputs, the outputs and the expected error. Fill the function to
15
15
This will be enforced with `flake8`. You can check that there is no flake8
16
16
errors by calling `flake8` at the root of the repo.
17
17
"""
18
+
18
19
import numpy as np
19
20
20
21
@@ -41,6 +42,19 @@ def max_index(X):
41
42
j = 0
42
43
43
44
# TODO
45
+ if not isinstance (X , np .ndarray ):
46
+ raise ValueError ("L'argument doit être une numpy array." )
47
+
48
+ forme = X .shape
49
+
50
+ if len (forme ) != 2 :
51
+ raise ValueError ("L'argument doit être en 2D." )
52
+
53
+ n_samples , n_features = forme
54
+
55
+ index = np .argmax (X )
56
+ i = int (index // n_features )
57
+ j = int (index % n_features )
44
58
45
59
return i , j
46
60
@@ -62,6 +76,11 @@ def wallis_product(n_terms):
62
76
pi : float
63
77
The approximation of order `n_terms` of pi using the Wallis product.
64
78
"""
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.
79
+ if n_terms == 0 :
80
+ return 2
81
+
82
+ wal_pro = 1
83
+ for i in range (1 , n_terms + 1 ):
84
+ wal_pro *= (4 * i ** 2 ) / ((4 * i ** 2 ) - 1 )
85
+
86
+ return wal_pro * 2.
0 commit comments