Skip to content

Commit 4318e1d

Browse files
committed
Fichier complété
1 parent d31f7ef commit 4318e1d

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

numpy_questions.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,16 @@ def max_index(X):
4040
i = 0
4141
j = 0
4242

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)
4453

4554
return i, j
4655

@@ -62,6 +71,15 @@ def wallis_product(n_terms):
6271
pi : float
6372
The approximation of order `n_terms` of pi using the Wallis product.
6473
"""
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

0 commit comments

Comments
 (0)