Skip to content

Commit c07cade

Browse files
JeanJean
Jean
authored and
Jean
committed
UP my solution
1 parent d31f7ef commit c07cade

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

numpy_questions.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ def max_index(X):
3939
"""
4040
i = 0
4141
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)
4448

4549
return i, j
4650

@@ -62,6 +66,11 @@ def wallis_product(n_terms):
6266
pi : float
6367
The approximation of order `n_terms` of pi using the Wallis product.
6468
"""
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

0 commit comments

Comments
 (0)