Skip to content

Commit ae60533

Browse files
committed
UP my solution
1 parent d31f7ef commit ae60533

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

numpy_questions.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ def max_index(X):
4242

4343
# TODO
4444

45+
if not isinstance(X, np.ndarray):
46+
raise ValueError("Input must be a numpy array.")
47+
if X.ndim != 2:
48+
raise ValueError("Input array must be 2D.")
49+
50+
max_idx = np.argmax(X)
51+
52+
i, j = divmod(max_idx, X.shape[1])
53+
4554
return i, j
4655

4756

@@ -64,4 +73,7 @@ def wallis_product(n_terms):
6473
"""
6574
# XXX : The n_terms is an int that corresponds to the number of
6675
# terms in the product. For example 10000.
67-
return 0.
76+
pi = 1
77+
for i in range(1, n_terms + 1):
78+
pi = pi * (4 * (i**2) / (4 * (i**2) - 1))
79+
return pi * 2

0 commit comments

Comments
 (0)