File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -39,8 +39,12 @@ def max_index(X):
39
39
"""
40
40
i = 0
41
41
j = 0
42
-
43
- # TODO
42
+ if not isinstance (X , np .ndarray ):
43
+ raise ValueError ("The input is not a numpy array" )
44
+ if len (X .shape ) != 2 :
45
+ raise ValueError ("The shape is not 2D" )
46
+ max = np .argmax (X )
47
+ i , j = np .unravel_index (max , X .shape )
44
48
45
49
return i , j
46
50
@@ -62,6 +66,11 @@ def wallis_product(n_terms):
62
66
pi : float
63
67
The approximation of order `n_terms` of pi using the Wallis product.
64
68
"""
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.
69
+ prod = 1 # Initialisation du produit
70
+ if n_terms > 0 :
71
+ for n in range (1 , n_terms + 1 ):
72
+ term = (4 * n ** 2 ) / (4 * n ** 2 - 1 )
73
+ prod *= term
74
+
75
+ # Multiplier par 2 pour obtenir l'approximation de pi
76
+ return 2 * prod
You can’t perform that action at this time.
0 commit comments