File tree Expand file tree Collapse file tree 1 file changed +22
-4
lines changed Expand file tree Collapse file tree 1 file changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,16 @@ def max_index(X):
40
40
i = 0
41
41
j = 0
42
42
43
- # TODO
43
+ # On vérifie que l'entrée est un tableau numpy
44
+ if not isinstance (X , np .ndarray ):
45
+ raise ValueError ("Input array must be 2d" )
46
+
47
+ # On vérifie que le tableau est en 2D
48
+ if X .ndim != 2 :
49
+ raise ValueError ("Input array must be 2d" )
50
+
51
+ # cherche l'indice du maximum
52
+ i , j = np .unravel_index (np .argmax (X ), X .shape )
44
53
45
54
return i , j
46
55
@@ -62,6 +71,15 @@ def wallis_product(n_terms):
62
71
pi : float
63
72
The approximation of order `n_terms` of pi using the Wallis product.
64
73
"""
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.
74
+ # On initialise le produit à 1
75
+ product = 1.0
76
+
77
+ # Formule de Wallis
78
+ for n in range (1 , n_terms + 1 ):
79
+ term = (4 * n ** 2 ) / ((4 * n ** 2 ) - 1 )
80
+ product *= term
81
+
82
+ # Pi est 2 fois ce produit
83
+ pi = 2 * product
84
+
85
+ return pi
You can’t perform that action at this time.
0 commit comments