Skip to content

Commit 9c8ca83

Browse files
committed
solution !
1 parent d31f7ef commit 9c8ca83

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

numpy_questions.py

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

43-
# TODO
44-
43+
if not isinstance(X, np.ndarray):
44+
raise ValueError("X should be a numpy array")
45+
if len(X.shape) != 2:
46+
raise ValueError("X should be a 2D array")
47+
i, j = np.unravel_index(np.argmax(X), X.shape)
4548
return i, j
4649

4750

@@ -64,4 +67,10 @@ def wallis_product(n_terms):
6467
"""
6568
# XXX : The n_terms is an int that corresponds to the number of
6669
# terms in the product. For example 10000.
70+
pi = 1
71+
for i in range(1, n_terms+1):
72+
pi *= (4*i**2)/(4*i**2 - 1)
73+
pi *= 2
74+
return pi
75+
6776
return 0.

0 commit comments

Comments
 (0)