Skip to content

Commit 88c2f7f

Browse files
ajout
1 parent d31f7ef commit 88c2f7f

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

numpy_questions.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def max_index(X):
2929
Returns
3030
-------
3131
(i, j) : tuple(int)
32-
The row and columnd index of the maximum.
32+
The row and column index of the maximum.
3333
3434
Raises
3535
------
@@ -39,9 +39,11 @@ def max_index(X):
3939
"""
4040
i = 0
4141
j = 0
42-
43-
# TODO
44-
42+
if type(X) is not np.ndarray:
43+
raise ValueError
44+
if len(X.shape) != 2:
45+
raise ValueError
46+
i, j = np.unravel_index(np.argmax(X), X.shape)
4547
return i, j
4648

4749

@@ -62,6 +64,12 @@ def wallis_product(n_terms):
6264
pi : float
6365
The approximation of order `n_terms` of pi using the Wallis product.
6466
"""
67+
6568
# XXX : The n_terms is an int that corresponds to the number of
6669
# terms in the product. For example 10000.
67-
return 0.
70+
if type(n_terms) is not int:
71+
raise TypeError
72+
product = 1
73+
for n in range(0, n_terms):
74+
product = product*((4*((n+1)**2))/(4*((n+1)**2)-1))
75+
return product*2

0 commit comments

Comments
 (0)