Skip to content

Commit 59b893f

Browse files
committed
Working properly
1 parent d31f7ef commit 59b893f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

numpy_questions.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ def max_index(X):
4040
i = 0
4141
j = 0
4242

43-
# TODO
43+
if not isinstance(X, np.ndarray) :
44+
raise ValueError
45+
if len(X.shape) != 2 :
46+
raise ValueError
47+
48+
index_linked = np.argmax(X).ravel()
49+
50+
i, j = np.unravel_index(index_linked, X.shape)
4451

4552
return i, j
4653

@@ -64,4 +71,10 @@ def wallis_product(n_terms):
6471
"""
6572
# XXX : The n_terms is an int that corresponds to the number of
6673
# terms in the product. For example 10000.
67-
return 0.
74+
if (n_terms==0) :
75+
pi = 1
76+
else :
77+
n = np.arange(1, n_terms +1, dtype=np.float64) # Generate n = 1, 2, ..., n_terms
78+
ratios = (4 * n**2) / ((2 * n - 1) * (2 * n + 1))
79+
pi = np.prod(ratios)
80+
return pi*2

0 commit comments

Comments
 (0)