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
@@ -40,7 +41,21 @@ def max_index(X):
40
41
i = 0
41
42
j = 0
42
43
44
+
43
45
# 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 )
44
59
45
60
return i , j
46
61
@@ -62,6 +77,11 @@ def wallis_product(n_terms):
62
77
pi : float
63
78
The approximation of order `n_terms` of pi using the Wallis product.
64
79
"""
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